Personalisation SDK, by MapmyIndia, is India's first O2O engagement tool that can 3X your customer engagement, retention and conversion.
MapmyIndia’s iOS Map SDK helps to embed MapmyIndia maps within your iOS application. Through customized raster tiles, you can add different map layers to your application and add bunch of controls and gestures to enhance map usability thus creating potent map based solutions for your customers.
Your MapmyIndia Maps SDK usage needs a set of license keys (get them here) and is governed by the API terms and conditions. As part of the terms and conditions, you cannot remove or hide the MapmyIndia logo and copyright information in your project.
The allowed SDK hits are described on the plans page. Note that your usage is shared between platforms, so the API hits you make from a web application, Android app or an iOS app all add up to your allowed daily limit.
#import <MMIFramework/MMIFramework.h>
[LicenceManager sharedInstance].restAPIKey=your_rest_api_key; [LicenceManager sharedInstance].mapSDKKey=your_java_script_key;
Add your MapmyIndia Map API keys to your AppDelegate.m as follows–
1) Add the following import statement.
#import <MapmyIndiaAPIKit/MapmyIndiaAPIKit.h>
import MapmyIndiaAPIKit
2) Add the following import statement.
To initialize SDK you have to set required keys. You can achieve this using
two ways.
First Way (Preferred):-
By adding following keys in Info.plist file of your project MapmyIndiaSDKKey, MapmyIndiaRestKey, MapmyIndiaAtlasClientId, MapmyIndiaAtlasClientSecret, MapmyIndiaAtlasGrantType,
Second Way:-
You can also set these required keys programmatically. Add the following to your application:didFinishLaunchingWithOptions: method, replacing restAPIKey and mapSDKKey with your own API keys:
[MapmyIndiaAccountManager setMapSDKKey:@.MAP SDK KEY.]; [MapmyIndiaAccountManager setRestAPIKey:@"REST API KEY.]; [MapmyIndiaAccountManager setAtlasClientId:@.ATLAS CLIENT ID"]; [MapmyIndiaAccountManager setAtlasClientSecret:@.ATLAS CLIENT SECRET.];[MGLAccountManager setAtlasGrantType:@.GRANT TYPE.]; //eg. client_credentials [MapmyIndiaAccountManager setAtlasAPIVersion:@.1.3.11"]; // Optional
MapmyIndiaAccountManager.setMapSDKKey("MAP SDK KEY") MapmyIndiaAccountManager.setRestAPIKey(.REST API KEY") MapmyIndiaAccountManager.setAtlasClientId("ATLAS CLIENT ID") MapmyIndiaAccountManager.setAtlasClientSecret("ATLAS CLIENT SECRET") MapmyIndiaAccountManager.setAtlasGrantType("GRANT TYPE.) //eg. client_credentials MapmyIndiaAccountManager.setAtlasAPIVersion(.1.3.11") // Optional
Note :- Contact with MapmyIndia support team to get Keys required to initialize SDK.
#import <MMIFramework/MMIFramework.h> @interface MapViewController : UIViewController { MMIMapView* mapView; } @end @implementation MapViewController - (void)viewDidLoad { [super viewDidLoad]; mapView = [MMIMapView alloc] initWithFrame:self.view.frame]; [self.view addSubview:mapView]; } @end
//Set zoom to 4 for country level display and 18 for house number display [mapView setZoom:14];
The following function will display user’s current location on the map.
mapView.showUserLocation=YES; NSLog(@"User's location: %@", mapView.userLocation);
The Map object should implement the methods of the MMIDelegate protocol corresponding to the events you wish it to receive. This delegate can also be used to detect map overlays selection. Delegate handles gesture events, tap on annotation (marker), long press on map and map center coordinates.
-(void)mapViewRegionDidChange:(MMIMapView *)mapView; -(void)afterMapMove:(MMIMapView *)map byUser:(BOOL)wasUserAction; -(void)afterMapZoom:(MMIMapView *)map byUser:(BOOL)wasUserAction; -(void)tapOnAnnotation:(MMIAnnotation *)annotation onMap:(MMIMapView *)mapView
To capture single tap on map events, use singleTapOnMap method from MMIDelegate -
- (void)singleTapOnMap:(MMIMapView *)map at:(CGPoint)point;
For long press event, use longPressOnMap method of MMIDelegate -
- (void)longPressOnMap:(MMIMapView *)map at:(CGPoint)point;
Add a Marker
To add a marker, create a MMIAnnotation object that includes a location, title/subtitle and markerImage etc.
MMIAnnotation* annotation=[[MMIAnnotation alloc] init]; annotation.latitude=28.526; annotation.longitude=78.568; annotation.title=@"Delhi" ; //the title is shown in the info window as described below [mapView addAnnotation:annotation];
Remove a Marker
[mapView removeAnnotation:annotation]; // to remove a single marker [mapView removeAllAnnotations]; // to clear all markers on map
Change default marker icon
annotation.markerImage=[UIImage imageNamed:@"placemarker.png"]; //formats supported - png,jpg annotation.makerSize=CGSizeMake(48, 48); //set any size that looks good with your image
Marker Opacity
MMIAnnotation* annotation=[[MMIAnnotation alloc] init]; annotation.latitude=28.123 annotation.longitude=78.563 annotation.opacity=0.5; [mapView addAnnotation:annotation];
Enable display of info windows on annotation tap event.
MMIAnnotation* annotation=[[MMIAnnotation alloc] init]; annotation.latitude=28.123 annotation.longitude=78.563 annotation.title=@"Welcome"; annotation.canShowCallout=YES; annotation.opacity=1.0;
To enable auto-clustering on all markers displayed on map, set the value to True. Default is False. See marker clustering in action in the samples bundled in the SDK.
mapView.clusteringEnabled=NO;
Add a Polyline
NSArray *locations = [NSArray arrayWithObjects: [[CLLocation alloc] initWithLatitude:28.54937553 longitude:77.26795197], [[CLLocation alloc] initWithLatitude:28.54939461 longitude:77.26816559], [[CLLocation alloc] initWithLatitude:28.54946899 longitude:77.26811981], [[CLLocation alloc] initWithLatitude:28.54972458 longitude:77.26800537],nil]; [mapView drawPolyLine:locations];
Remove a Polyline
[mapView removePolyLine];
Customize a Polyline
Change width of polyline -
mapView.polylineWidth=4.0;
Change color of polyline –
mapView.polylineColor=[UIColor greenColor];
Add a Polygon
NSMutableArray* polygonVertices = [[NSMutableArray alloc] initWithCapacity:50]; CLLocation* location1=[[CLLocation alloc] initWithLatitude:26.613434longitude:75.758556]; CLLocation* location2=[[CLLocation alloc] initWithLatitude:26.311922longitude:76.492635]; CLLocation* location3=[[CLLocation alloc] initWithLatitude:26.230916longitude:76.130366]; CLLocation* location4=[[CLLocation alloc] initWithLatitude:26.364601longitude:75.832132]; CLLocation* location5=[[CLLocation alloc] initWithLatitude:26.613434longitude:75.758556]; [polygonVertices addObject:location1]; [polygonVertices addObject:location2]; [polygonVertices addObject:location3]; [polygonVertices addObject:location4]; [polygonVertices addObject:location5]; [mapViewdrawPolyLine:polygonVertices];
Add a Circle
You must specify the following parameters to add a circle on the map –
MMIAnnotation* annotation=[[MMIAnnotationalloc] init]; annotation.latitude=28.526; annotation.longitude=78.568; annotation.radiusInMeters=500; annotation.lineWidthInPixels=5;
annotation.lineColor=[UIColor redColor]; //change the stroke color of the circle annotation.fillColor=[UIColor colorWithRed:.5 green:.466 blue:.733 alpha:.25]; //change the fill color of the circle
The following search services are available as part of the SDK bundled by default (Make sure you include following import in your code) –
#import <MMIFramework/MMIFramework.h>
You can read more on MapmyIndia's Geocoding API. To geocode an address, create an instance of GeocodeManager class and call the getPlace method –
GeocodeManager *managerObject = [[GeocodeManager alloc] init]; [managerObject getPlace:@“New Delhi” completion:^(NSDictionary *result,NSError* error){ // if error is nil, then result is success. // response includes responseCode,version and results Array }];
You can find address for a point on the map by using the MapmyIndia Maps Reverse Geocoding API. Pass the GeoPoint to the ReverseGeocodeManager class –
ReverseGeocodeManager *reverseGeoCodeManagerObject=[[ReverseGeocodeManager alloc]init]; [reverseGeoCodeManagerObject getPlace:CLLocationCoordinate2DMake(startPoint, finalPoint) completion:^(NSDictionary *result,NSError* error){ // if error is nil, then result is success. // response is the results array }];
Routing and displaying driving directions on map, including instructions for navigation, distance to destination, traffic etc. are few of the most important parts of developing a map based application. This REST API calculates driving routes between specified locations including via points based on route type(fastest or shortest), includes delays for traffic congestion , and is capable of handling additional route parameters like: type of roads to avoid, travelling vehicle type etc.
DirectionManager *directionManagerObject=[[DirectionManager alloc]init]; [directionManagerObject getInstance].with_advices=@"1"; //if you want full textual advice in the response [directionManagerObject getDirections:CLLocationCoordinate2DMake(28.568, 78.573) endPoint:CLLocationCoordinate2DMake(28.325, 78.845) viaPoints:@[[NSString stringWithFormat:@"%f,%f",28.123,78.451]] completion:^(NSDictionary *result,NSError* error){ // if error is nil, then result is success. // result is response }];
Adding driving directions API would help to add predicted travel time & duration from a given origin point to a number of points. The Driving Distance Matrix API provides driving distance and estimated time to go from a start point to multiple destination points, based on recommended routes from MapmyIndia Maps and traffic flow conditions
DistanceManager*distanceManagerObject=[[DistanceManager alloc]init]; [distanceManagerObject getDistance:CLLocationCoordinate2DMake(28.568, 78.573) points:@[[NSString stringWithFormat:@"%f,%f",28.123,78.451]] completion:^(NSDictionary *result,NSError* error){ // if error is nil, then result is success. // result is response }];
The Autosuggest helps users to complete queries faster by adding intelligent search capabilities to your iOS mobile app. It takes a human readable query such as place name, address or eLoc and returns a list of results.
Class used for auto suggest search is MapmyIndiaAutoSuggestManager. Create a MapmyIndiaAutoSuggestManager object using your rest key or alternatively, you can place your rest key in the MapmyIndiaRestKey key of your application.s Info.plist file, then use the shared instance of MapmyIndiaAutoSuggestManager class.
To perform auto suggest use MapmyIndiaAutoSearchAtlasOptions class to pass query parameter to get auto suggest search with an option to pass region in parameter withRegion, which is an enum of type MMIRegionTypeIdentifier. If no value is passed for region, It will take default value which is India.
MMIRegionTypeIdentifier is used to validate and get result for different countries. Currently five countries are supported including India which are Sri Lanka, India, Bhutan, Bangladesh, Nepal.
Additionally you can also set location and zoom in object of MapmyIndiaAutoSearchAtlasOptions. Where
In response of auto suggest search either you will receive an error or an array of MapmyIndiaAtlasSuggestion, Where MapmyIndiaAtlasSuggestion is derived from MapmyIndiaSuggestion class. Yo will find below useful properties in suggestion object :
Example
MapmyIndiaAutoSuggestManager * autoSuggestManager = [MapmyIndiaAutoSuggestManager sharedManager] or MapmyIndiaAutoSuggestManager *autoSearchManager = [[MapmyIndiaAutoSuggestManager alloc] initWithRestKey:MapmyIndiaAccountManager.restAPIKey clientId:MapmyIndiaAccountManager.atlasClientId clientSecret:MapmyIndiaAccountManager.atlasClientSecret grantType:MapmyIndiaAccountManager.atlasGrantType] MapmyIndiaAutoSearchAtlasOptions * autoSuggestOptions = [[MapmyIndiaAutoSearchAtlasOptions alloc] initWithQuery:@"mmi000" withRegion:MMIRegionTypeIdentifierDefault]; [autoSuggestManager getAutoSuggestionsWithOptions:autoSearchOptions completionHandler:^(NSArray<MapmyIndiaAtlasSuggestion *> * _Nullable suggestions, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (suggestions.count > 0) { NSLog(@"Auto Suggest %@%@", suggestions[0].latitude,suggestions[0].longitude); self.resultsLabel.text = suggestions[0].placeAddress; } else { self.resultsLabel.text = @"No results"; } }];
let autoSuggestManager = MapmyIndiaAutoSuggestManager.shared Or let autoSuggestManager = MapmyIndiaAutoSuggestManager(restKey: MapmyIndiaAccountManager.restAPIKey(), clientId: MapmyIndiaAccountManager.atlasClientId(), clientSecret: MapmyIndiaAccountManager.atlasClientSecret(), grantType: MapmyIndiaAccountManager.atlasGrantType()) let autoSuggestOptions = MapmyIndiaAutoSearchAtlasOptions(query: "mmi000", withRegion: .india) autoSuggestOptions.location = CLLocation(latitude: 28.2323234, longitude: 72.3434123) autoSuggestOptions.zoom = 5 autoSuggestManager.getAutoSuggestions(autoSuggestOptions) { (suggestions, error) in if let error = error { NSLog("%@", error) } else if let suggestions = suggestions, !suggestions.isEmpty { print("Auto Suggest: \(suggestions[0].latitude ?? 0),\ (suggestions[0].longitude ?? 0)") self.resultsLabel.text = suggestions[0].placeAddress } else { self.resultsLabel.text = "No results"
The Reverse Geocoding API converts geographical coordinates (latitude/longitude) into the closest matching address. It provides real addresses along with nearest popular landmark for any such geo-positions on the map.
Class used for geocode is MapmyIndiaReverseGeocodeManager. Create a MapmyIndiaReverseGeocodeManager object using your rest key or alternatively, you can place your rest key in the MapmyIndiaRestKey key of your application.s Info.plist file, then use the shared instance of MapmyIndiaReverseGeocodeManager class.
To perform auto suggest use MapmyIndiaReverseGeocodeOptions class to pass coordinates as parameters to reverse geocode with an option to pass region in parameter withRegion, which is an enum of type MMIRegionTypeIdentifier. If no value is passed for region, It will take default value which is India.
MMIRegionTypeIdentifier is used to validate and get result for different countries. Currently five countries are supported including India which are Sri Lanka, India, Bhutan, Bangladesh, Nepal.
In response of geocode search either you will receive an error or an array of MapmyIndiaGeocodedPlacemark. Yo will find below useful properties in suggestion object :
Example
MapmyIndiaReverseGeocodeManager * reverseGeocodeManager = [MapmyIndiaReverseGeocodeManager sharedManager]; Or MapmyIndiaReverseGeocodeManager * reverseGeocodeManager = [[MapmyIndiaReverseGeocodeManager alloc] initWithRestKey:MapmyIndiaAccountManager.restAPIKey]; MapmyIndiaReverseGeocodeOptions *revOptions =[[MapmyIndiaReverseGeocodeOptions alloc] initWithCoordinate:self.mapView.centerCoordinate withRegion:MMIRegionTypeIdentifierDefault]; [reverseGeocodeManager reverseGeocodeWithOptions:revOptions completionHandler:^(NSArray<MapmyIndiaGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (placemarks.count > 0) { NSLog(@"Reverse Geocode %@,%@", placemarks[0].latitude,placemarks[0].longitude); self.resultsLabel.text = placemarks[0].formattedAddress; } else { self.resultsLabel.text = @"No results"; } }];
let reverseGeocodeManager = MapmyIndiaReverseGeocodeManager.shared Or let reverseGeocodeManager = MapmyIndiaReverseGeocodeManager(restKey: MapmyIndiaAccountManager.restAPIKey()) let revOptions = MapmyIndiaReverseGeocodeOptions(coordinate: mapView.centerCoordinate, withRegion: .india) reverseGeocodeManager.reverseGeocode(revOptions) { (placemarks, attribution, error) in if let error = error { NSLog("%@", error) } else if let placemarks = placemarks, !placemarks.isEmpty { print("Reverse Geocode: \(placemarks[0].latitude ?? ""),\ (placemarks[0].longitude ?? "")") self.resultsLabel.text = placemarks[0].formattedAddress } else { self.resultsLabel.text = "No results" } }
Nearby search, enables you to add discovery and search of nearby POIs by searching for a generic keyword used to describe a category of places or via the unique code assigned to that category.
Class used for geocode is MapmyIndiaNearByManager. Create a MapmyIndiaNearByManager object using your rest key or alternatively, you can place your rest key in the MapmyIndiaRestKey key of your application.s Info.plist file, then use the shared instance of MapmyIndiaNearByManager class.
To perform auto suggest use MapmyIndiaNearbyAtlasOptions class to pass keywords/categories and a reference location as parameters to get Nearby search results with an option to pass region in parameter withRegion, which is an enum of type MMIRegionTypeIdentifier. If no value is passed for region, It will take default value which is India.
MMIRegionTypeIdentifier is used to validate and get result for different countries. Currently five countries are supported including India which are Sri Lanka, India, Bhutan, Bangladesh, Nepal.
Additionally you can also set location and zoom in object of MapmyIndiaAutoSearchAtlasOptions. Where
In response of geocode search either you will receive an error or an array of MapmyIndiaGeocodedPlacemark. Yo will find below useful properties in suggestion object :
Example
MapmyIndiaNearByManager * nearByManager = [MapmyIndiaNearByManager sharedManager]; Or MapmyIndiaNearByManager * nearByManager = [[MapmyIndiaNearByManager alloc] initWithRestKey:MapmyIndiaAccountManager.restAPIKey clientId:MapmyIndiaAccountManager.atlasClientId clientSecret:MapmyIndiaAccountManager.atlasClientSecret grantType:MapmyIndiaAccountManager.atlasGrantType]; MapmyIndiaNearbyAtlasOptions *nearByOptions = [[MapmyIndiaNearbyAtlasOptions alloc] initWithQuery:@"Shoes" location: [[CLLocation alloc] initWithLatitude:28.543014 longitude:77.242342] withRegion:MMIRegionTypeIdentifierDefault]; [nearByManager getNearBySuggestionsWithOptions:nearByOptions completionHandler:^(NSArray<MapmyIndiaAtlasSuggestion *> * _Nullable suggestions, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (suggestions.count > 0) { NSLog(@"Nearby %@%@", suggestions[0].latitude,suggestions[0].longitude); self.resultsLabel.text = suggestions[0].placeAddress; } else { self.resultsLabel.text = @"No results"; } }];
let nearByManager = MapmyIndiaNearByManager.shared Or let nearByManager = MapmyIndiaNearByManager(restKey: MapmyIndiaAccountManager.restAPIKey(), clientId: MapmyIndiaAccountManager.atlasClientId(), clientSecret: MapmyIndiaAccountManager.atlasClientSecret(), grantType: MapmyIndiaAccountManager.atlasGrantType()) let nearByOptions = MapmyIndiaNearbyAtlasOptions(query: "Shoes", location: CLLocation(latitude: 28.543014, longitude: 77.242342), withRegion: .india) nearByManager.getNearBySuggestions(nearByOptions) { (suggestions, error) in if let error = error { NSLog("%@", error) } else if let suggestions = suggestions, !suggestions.isEmpty { print("Near by: \(suggestions[0].latitude ?? 0),\ (suggestions[0].longitude ?? 0)") self.resultsLabel.text = suggestions[0].placeAddress } else { self.resultsLabel.text = "No results" } }
The MapmyIndia eLoc is a simple, standardised and precise pan-India digital address system. Every location has been assigned a unique digital address or an eLoc. The Place Detail can be used to extract the details of a place with the help of its eLoc i.e. a 6 digit code.
Class used for geocode is MapmyIndiaPlaceDetailManager. Create a MapmyIndiaPlaceDetailManager object using your rest key or alternatively, you can place your rest key in the MapmyIndiaRestKey key of your application.s Info.plist file, then use the shared instance of MapmyIndiaPlaceDetailManager class.
To perform auto suggest use MapmyIndiaPlaceDetailGeocodeOptions class to pass digital address code (eLoc/PlaceId) as parameters to get eLoc Detail results with an option to pass region in parameter withRegion, which is an enum of type MMIRegionTypeIdentifier. If no value is passed for region, It will take default value which is India.
MMIRegionTypeIdentifier is used to validate and get result for different countries. Currently five countries are supported including India which are Sri Lanka, India, Bhutan, Bangladesh, Nepal.
In response of geocode search either you will receive an error or an array of MapmyIndiaGeocodedPlacemark. Yo will find below useful properties in suggestion object :
Example
MapmyIndiaPlaceDetailManager * placeDetailManager = [MapmyIndiaPlaceDetailManager sharedManager]; Or MapmyIndiaPlaceDetailManager * placeDetailManager = [[MapmyIndiaPlaceDetailManager alloc] initWithRestKey:MapmyIndiaAccountManager.restAPIKey]; MapmyIndiaPlaceDetailGeocodeOptions *placeOptions = [[MapmyIndiaPlaceDetailGeocodeOptions alloc] initWithPlaceId:@"mmi000" withRegion:MMIRegionTypeIdentifierDefault]; [placeDetailManager getPlaceDetailWithOptions:placeOptions completionHandler:^(NSArray<MapmyIndiaGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (placemarks.count > 0) { NSLog(@"Place Detail Geocode %@%@", placemarks[0].latitude,placemarks[0].longitude); self.resultsLabel.text = placemarks[0].formattedAddress; } else { self.resultsLabel.text = @"No results"; } }];
let placeDetailManager = MapmyIndiaPlaceDetailManager.shared Or let placeDetailManager = MapmyIndiaPlaceDetailManager(restKey: MapmyIndiaAccountManager.restAPIKey()) let placeOptions = MapmyIndiaPlaceDetailGeocodeOptions(placeId: "mmi000", withRegion: .india) placeDetailManager.getPlaceDetail(placeOptions) { (placemarks, attribution, error) in if let error = error { NSLog("%@", error) } else if let placemarks = placemarks, !placemarks.isEmpty { print("Place Detail Geocode: \(placemarks[0].latitude ?? ""),\(placemarks[0].longitude ?? "")") self.resultsLabel.text = placemarks[0].formattedAddress } else { self.resultsLabel.text = "No results" } }
The Geocoding API converts real addresses into these geographic coordinates (latitude/longitude) to be placed on a map, be it for any street, area, postal code, POI or a house number etc.
Class used for geocode is MapmylndiaAtlasGeocodeManager. To create instance of MapmylndiaAtlasGeocodeManager initialize using your rest key, clientld, clientSe cret , grantTy pe or use shared instance of MapmylndiaAtlasGeocodeManager after setting key values MapmylndiaRestKey, MapmylndiaAtlasCl ient ld, MapmylndiaAtlasCl ientSecret, MapmylndiaAtlasGrantType in your application's lnfo.plist file.
To perform geocode use 'getGeocodeResults' method of instance of MapmylndiaAtlasGeocodeManager class which accepts an instance of MapmylndiaAtlasGeocodeOptions class. To create instance of MapmylndiaAtlasGeocodeOptions, pass any address as query parameters to geocode.
The below are supported input queries:
(a) query: The address of a location (e.g. 237 Okhla Phase-Ill).
Additionally you can also set some other parameters in object of MapmylndiaAtlasGeocodeOptions to get some specific results. Which are:
(a) maximumResu ltCount: The number of results which needs to be return in response.
In response of geocode search either you will receive an error or an array of MapmylndiaGeocodedPlacemark. Yo will find below useful properties in suggestion object :
MapmyindiaAtlasGeocodeManager * atlasGeocodeManager = {MapmyindiaAtlasGeocodeManager sharedManager}; or MapmyindiaAtlasGeocodeManager * atlasGeocodeManager = {{MapmyindiaAtlasGeocodeManager alloc} initWithRestKey:MapmyindiaAccountManager.restAPIKey clientid:MapmyindiaAccountManager.atlasClientid clientSecret:MapmyindiaAccountManager.atlasClientSecret grantType:MapmyindiaAccountManager.atlasGrantType]; MapmyindiaAtlasGeocodeOptions *atlasGeocodeOptions = {{MapmyindiaAtlasGeocodeOptions alloc} initWithQuery: @"68 mapmyindia" withRegion:MMIRegionTypeidentifierDefault]; {atlasGeocodeManager getGeocodeResultsWithOptions:atlasGeocodeOptions completionHandler: A(MapmyindiaAtlasGeocodeAPIResponse * _Nullable response, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (response!= nil && response.placemarks.count > 0) { NSLog(@"Forward Geocode %@%@", response.placemarks[0J.latitude, response.placemarks[0J.longitude); if (error) { } else { NSLog(@"No results"); } }];
let atlasGeocodeManager = MapmyindiaAtlasGeocodeManager.shared or let atlasGeocodeManager = MapmyindiaAtlasGeocodeManager(restKey: MapmyindiaAccountManager.restAPIKey(), clientid: MapmyindiaAccountManager.atlasClientid(), clientSecret: MapmyindiaAccountManager.atlasClientSecret(), grantType: MapmyindiaAccountManager.atlasGrantType()) let atlasGeocodeOptions = MapmyindiaAtlasGeocodeOptions(query: "mapmyindia ", withRegion: .default) atlasGeocodeOptions.maximumResultCount = 10 atlasGeocodeManager.getGeocodeResults(atlasGeocodeOptions) { (response, error) in if let error = error { NSLog("%@", error) } else if let result = response, let placemarks = result.placemarks, placemarks.count > 0 { print("Atlas Geocode: \(placemarks[OJ.latitude), \ (placemarks[OJ.longitude)") } else { print("No results") } }
The Distance matrix computes the distance and duration of a route between a source/primary position and a list of all supplied secondary positions, it provides a matrix response of distance and duration.
Class used for driving distance is MapmyIndiaDrivingDistanceMatrixManager. Create a MapmyIndiaDrivingDistanceMatrixManager object using your rest key or alternatively, you can place your rest key in the MapmyIndiaRestKey key of your application’s Info.plist file, then use the shared instance of MapmyIndiaDrivingDistanceManager class.
To perform this operation use MapmyIndiaDrivingDistanceMatrixOptions class to pass center location and points parameters.
To use API Distance Matrix ETA, to get duration inclusive of traffic for a distance between locations use parameter ‘withTraffic’ as described below:
Additionally you can pass some other parameters to get filtered/specific results. Which are as :
Note: It is no use of routeType and region value if you are using Distance Matrix ETA i.e if value of withTraffic is true.
In response either you will receive an error or an object of MapmyIndiaDrivingDistanceMatrixResponse where structure of object is as described below:
MapmyIndiaDrivingDistanceMatrixManager *distanceMatrixManager = [MapmyIndiaDrivingDistanceMatrixManager sharedManager]; MapmyIndiaDrivingDistanceMatrixOptions *distanceMatrixOptionsETA = [[MapmyIndiaDrivingDistanceMatrixOptions alloc] initWithCenter:[[CLLocation alloc] initWithLatitude: 28.543014 longitude:77.242342] points:[NSArray arrayWithObjects: [[CLLocation alloc] initWithLatitude:28.520638 longitude:77.201959], [[CLLocation alloc] initWithLatitude:28.511810 longitude: 77.252773], nil]]; distanceMatrixOptionsETA.withTraffic = YES; [distanceMatrixManager getResultWithOptions:distanceMatrixOptionsETA completionHandler:^(MapmyIndiaDrivingDistanceMatrixResponse * _Nullable result, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (result != nil && result.results != nil) { NSArray<NSNumber *> *durations = result.results.durations.firstObject; NSArray<NSNumber *> *distances = result.results.distances.firstObject; NSUInteger pointCount = [distanceMatrixOptions points].count; for (int i = 0; i < pointCount; i++) { if (i < durations.count && i < distances.count) { NSLog(@"Driving Distance Matrix ETA %d duration: %@, distance: %@", i, durations[i], distances[i]); } } } else { NSLog(@"No results"); }} }];
let distanceMatrixManager = MapmyIndiaDrivingDistanceMatrixManager.shared let distanceMatrixOptionsETA = MapmyIndiaDrivingDistanceMatrixOptions(center: CLLocation(latitude: 28.543014, longitude: 77.242342), points: [CLLocation(latitude: 28.520638, longitude: 77.201959), CLLocation(latitude: 28.511810, longitude: 77.252773)]) distanceMatrixOptionsETA.withTraffic = true distanceMatrixManager.getResult(distanceMatrixOptionsETA) { (result, error) in if let error = error { NSLog("%@", error) } else if let result = result, let results = result.results, let durations = results.durations?[0], let distances = results.distances?[0] { let pointCount = distanceMatrixOptionsETA.points?.count ?? -1 for i in 0.. if i < durations.count && i < distances.count { print("Driving Distance Matrix ETA \(i): duration: \(durations[i]) distance: \(distances[i])") } } } else { print("No results") } }
To finds the route between given coordinates in the supplied order using to mode of route calculation i.e. optimal and shortest. Supported region (countries) are India, Sri Lanka, Nepal, Bangladesh and Bhutan.
Use Directions to get route between locations. You can use it either by creating object using your rest key or use shared instance of Directions class by setting rest key in the 'MapmylndiaRestKey' key of your application's lnfo.plist file.
To perform this operation use object of RouteOptions class as request to pass source location and destination locations and other parameters.
To use Route ETA feature, use 'profileldentifier' parameter of object of 'RouteOptions' and set its value to automobileWithTraffic to get route with durations(inclusive of traffic). Parameter 'profileldentifier' is described below:
Additionally you can set some more parameters on instance of RouteOptions to get filtered/specific results. Which are as :
let options = RouteOptions(waypoints: [ Waypoint(coordinate: CLLocationCoordinate2D(latitude: 28.551078, longitude: 77.268968), name: "MapmyIndia"), Waypoint(coordinate: CLLocationCoordinate2D(latitude: 28.565065, longitude: 77.234193), name: "Moolchand"), ])
MapmyIndiaRouteTripManager *routeTripManager = [MapmyIndiaRouteTripManager sharedManager]; Or MapmyIndiaRouteTripManager *routeTripManager = [[MapmyIndiaRouteTripManager alloc] initWithRestKey:MapmyIndiaAccountManager.restAPIKey]; MapmyIndiaRouteTripOptions *routeOptions = [[MapmyIndiaRouteTripOptions alloc] initWithStartLocation:[[CLLocation alloc] initWithLatitude:28.551052 longitude:77.268918] destinationLocation:[[CLLocation alloc] initWithLatitude:28.630195 longitude:77.218119]]; [routeOptions setRouteType:MMIDistanceRouteTypeQuickest]; [routeOptions setVehicleType:MMIDistanceVehicleTypePassenger]; [routeOptions setAvoids:MMIDistanceAvoidsTypeAvoidToll]; [routeOptions setWithAdvices:true]; [routeOptions setWithAlternatives:true]; [routeTripManager getResultWithOptions:routeOptions completionHandler:^(MapmyIndiaTripResult * _Nullable result, NSString * _Nullable attribution, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (result) { NSLog(@"Driving Route %@", result.status); if (result.alternatives.count > 0) { NSLog(@"Driving Route Alternatives %@, %@",result.alternatives[0].duration, result.alternatives[0].length); if (result.alternatives[0].advices.count > 0) { NSLog(@"Alternatives advices: %ld",result.alternatives[0].advices.count); NSLog(@"Alternatives advices Text: %@",result.alternatives[0].advices[0].text); } } if (result.trips.count > 0) { NSLog(@"Driving Route Alternatives %@, %@",result.trips[0].duration, result.trips[0].length); if (result.trips[0].advices.count > 0) { NSLog(@"Trips advices: %ld",result.trips[0].advices.count); } } self.resultsLabel.text = [result.status stringValue]; } else { self.resultsLabel.text = @"No results"; } }];
Directions.shared.calculate(options) { (waypoints, routes, error) in guard error == nil else { print("Error calculating directions: \(error!)") return { if let route = routes?.first, let leg = route.legs.first { self.currentRouteLeg = leg print("Route via \(leg):") let distanceFormatter = LengthFormatter() let formattedDistance = distanceFormatter.string(fromMeters: route.distance) let travelTimeFormatter = DateComponentsFormatter() travelTimeFormatter.unitsStyle = .short let formattedTravelTime = travelTimeFormatter.string(from: route.expectedTravelTime) print("Distance: \(formattedDistance); ETA: \(formattedTravelTime!)") for step in leg.steps { print("\(step.instructions)") if step.distance > 0 { let formattedDistance = distanceFormatter.string(fromMeters: step.distance) print("— \(formattedDistance) —") } } if route.coordinateCount > 0 { // Convert the route’s coordinates into a polyline. var routeCoordinates = route.coordinates! let routeLine = MGLPolyline(coordinates: & routeCoordinates, count: route.coordinateCount) // Add the polyline to the map and fit the viewport to the polyline. self.mapView.addAnnotation(routeLine) self.mapView.setVisibleCoordinates(& routeCoordinates, count: route.coordinateCount, edgePadding: .zero, animated: true) } } }
The Geocoding API converts real addresses into these geographic coordinates (latitude/longitude) to be placed on a map, be it for any street, area, postal code, POI or a house number etc.
Class used for geocode is MapmyIndiaGeocodeManager. Create a MapmyIndiaGeocodeManager object using your rest key or alternatively, you can place your rest key in the MapmyIndiaRestKey key of your application.s Info.plist file, then use the shared instance of MapmyIndiaGeocodeManager class.
To perform auto suggest use MapmyIndiaForwardGeocodeOptions class to pass any address as query parameters to geocode with an option to pass region in parameter withRegion, which is an enum of type MMIRegionTypeIdentifier. If no value is passed for region, It will take default value which is India.
MMIRegionTypeIdentifier is used to validate and get result for different countries. Currently five countries are supported including India which are Sri Lanka, India, Bhutan, Bangladesh, Nepal.
The below are supported input queries:
Additionally you can also set some other parameters in object of MapmyIndiaNearbyAtlasOptions to get some specific results. Which are:
pincode: The pin-code of area (e.g. 110020).
In response of geocode search either you will receive an error or an array of MapmyIndiaGeocodedPlacemark. Yo will find below useful properties in suggestion object :
Example
MapmyIndiaGeocodeManager * geocodeManager = [MapmyIndiaGeocodeManager sharedManager]; Or MapmyIndiaGeocodeManager * geocodeManager = [[MapmyIndiaGeocodeManageralloc] initWithRestKey:MapmyIndiaAccountManager.restAPIKey]; MapmyIndiaForwardGeocodeOptions *forOptions = [[MapmyIndiaForwardGeocodeOptions alloc] initWithQuery: @"237 mapmyindia" withRegion:MMIRegionTypeIdentifierDefault]; [geocodeManager geocodeWithOptions:forOptions completionHandler:^(NSArray<MapmyIndiaGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (placemarks.count > 0) { NSLog(@"Forward Geocode %@%@", placemarks[0].latitude,placemarks[0].longitude); self.resultsLabel.text = placemarks[0].formattedAddress; } else { self.resultsLabel.text = @"No results"; } }];
let geocodeManager = MapmyIndiaGeocodeManager.shared Or let geocodeManager = MapmyIndiaGeocodeManager(restKey: MapmyIndiaAccountManager.restAPIKey()) let forOptions = MapmyIndiaForwardGeocodeOptions(query: "237 mapmyindia", withRegion: .india) geocodeManager.geocode(forOptions) { (placemarks, attribution, error) in if let error = error { NSLog("%@", error) } else if let placemarks = placemarks, !placemarks.isEmpty { print("Forward Geocode: \(placemarks[0].latitude ?? ""),\ (placemarks[0].longitude ?? "")") self.resultsLabel.text = placemarks[0].formattedAddress } else { self.resultsLabel.text = "No results" } }
The Driving Distance provides driving distance and estimated time to go from a start point to multiple destination points, based on recommended routes from MapmyIndia Maps and traffic flow conditions.
Class used for driving distance is MapmyIndiaDrivingDistanceManager. Create a MapmyIndiaDrivingDistanceManager object using your rest key or alternatively, you can place your rest key in the MapmyIndiaRestKey key of your application.s Info.plist file, then use the shared instance of MapmyIndiaDrivingDistanceManager class.
To perform auto suggest use MapmyIndiaDrivingDistanceOptions class to pass center location and points parameters. Where Driving distance will give distance for each point to center location.
Additionally you can pass some other parameters to get filtered/specific results. Which are as :
In response of Driving Distance either you will receive an error or an array of MapmyIndiaDrivingDistancePlacemark respectively result of each point passed in request. You will find below useful properties in placemarks object :
Example
MapmyIndiaDrivingDistanceManager * distanceManager = [MapmyIndiaDrivingDistanceManager sharedManager]; Or MapmyIndiaDrivingDistanceManager * distanceManager = [[MapmyIndiaDrivingDistanceManager alloc] initWithRestKey:MapmyIndiaAccountManager.restAPIKey]; MapmyIndiaDrivingDistanceOptions *distanceOptions = [[MapmyIndiaDrivingDistanceOptions alloc] initWithCenter:[[CLLocation alloc] initWithLatitude:28.543014 longitude:77.242342] points:[NSArray arrayWithObjects: [[CLLocation alloc] initWithLatitude:28.520638 longitude: 77.201959], nil]]; [distanceManager getResultWithOptions:distanceOptions completionHandler:^(NSArray<MapmyIndiaDrivingDistancePlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (placemarks.count > 0) { NSLog(@"Driving Distance %@,%@", placemarks[0].duration, placemarks[0].length); self.resultsLabel.text = [placemarks[0].status stringValue]; } else { self.resultsLabel.text = @"No results"; } }];
let distanceManager = MapmyIndiaDrivingDistanceManager.shared Or let distanceManager = MapmyIndiaDrivingDistanceManager(restKey: MapmyIndiaAccountManager.restAPIKey()) let distanceOptions = MapmyIndiaDrivingDistanceOptions(center: CLLocation(latitude: 28.543014, longitude: 77.242342), points: [CLLocation(latitude: 28.520638, longitude: 77.201959)]) distanceManager.getResult(distanceOptions) { (placemarks, attribution, error) in if let error = error { NSLog("%@", error) } else if let placemarks = placemarks, !placemarks.isEmpty { print("Driving Distance: \(placemarks[0].duration),\ (placemarks[0].length)") self.resultsLabel.text = "\(placemarks[0].duration)" } else { self.resultsLabel.text = "No results" } }
This will help to calculates driving routes between specified locations including via points based on route type(fastest or shortest), includes delays for traffic congestion , and is capable of handling additional route parameters like: type of roads to avoid, travelling vehicle type etc.
Class used for driving distance is MapmyIndiaRouteTripManager. Create a MapmyIndiaRouteTripManager object using your rest key or alternatively, you can place your rest key in the MapmyIndiaRestKey key of your application.s Info.plist file, then use the shared instance of MapmyIndiaRouteTripManager class.
To perform auto suggest use MapmyIndiaRouteTripOptions class to pass start location and destination location parameters.
Additionally you can pass some other parameters to get some filtered/specific results. Which are as:
All Parameters defined below are optional parameters and default values will be considered if not sent.
In response of Route search either you will receive an error or an object of MapmyIndiaTripResult. You will find below useful properties in placemarks object :
Note:
Example
MapmyIndiaRouteTripManager *routeTripManager = [MapmyIndiaRouteTripManager sharedManager]; Or MapmyIndiaRouteTripManager *routeTripManager = [[MapmyIndiaRouteTripManager alloc] initWithRestKey:MapmyIndiaAccountManager.restAPIKey]; MapmyIndiaRouteTripOptions *routeOptions = [[MapmyIndiaRouteTripOptions alloc] initWithStartLocation:[[CLLocation alloc] initWithLatitude:28.551052 longitude:77.268918] destinationLocation:[[CLLocation alloc] initWithLatitude:28.630195 longitude:77.218119]]; [routeOptions setRouteType:MMIDistanceRouteTypeQuickest]; [routeOptions setVehicleType:MMIDistanceVehicleTypePassenger]; [routeOptions setAvoids:MMIDistanceAvoidsTypeAvoidToll]; [routeOptions setWithAdvices:true]; [routeOptions setWithAlternatives:true]; [routeTripManager getResultWithOptions:routeOptions completionHandler:^(MapmyIndiaTripResult * _Nullable result, NSString * _Nullable attribution, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); } else if (result) { NSLog(@"Driving Route %@", result.status); if (result.alternatives.count > 0) { NSLog(@"Driving Route Alternatives %@, %@",result.alternatives[0].duration, result.alternatives[0].length); if (result.alternatives[0].advices.count > 0) { NSLog(@"Alternatives advices: %ld",result.alternatives[0].advices.count); NSLog(@"Alternatives advices Text: %@",result.alternatives[0].advices[0].text); } } if (result.trips.count > 0) { NSLog(@"Driving Route Alternatives %@, %@",result.trips[0].duration, result.trips[0].length); if (result.trips[0].advices.count > 0) { NSLog(@"Trips advices: %ld",result.trips[0].advices.count); } } self.resultsLabel.text = [result.status stringValue]; } else { self.resultsLabel.text = @"No results"; } }];
let routeTripManager = MapmyIndiaRouteTripManager.shared Or let routeTripManager = MapmyIndiaRouteTripManager(restKey: MapmyIndiaAccountManager.restAPIKey()) let routeOptions = MapmyIndiaRouteTripOptions(startLocation: CLLocation(latitude: 28.551052, longitude: 77.268918), destinationLocation: CLLocation(latitude: 28.630195, longitude: 77.218119)) routeOptions.withAdvices = true routeOptions.withAlternatives = true routeOptions.avoids = .avoidToll routeOptions.routeType = .shortest routeOptions.vehicleType = .passenger routeTripManager.getResult(routeOptions) { (result, attribution, error) in if let error = error { NSLog("%@", error) } else if let result = result { print("Driving Route: \(result.status)")} if let alternatives = result.alternatives, ! alternatives.isEmpty { print("Driving Route Alternatives: \ (alternatives[0].duration),\(alternatives[0].length)") } if let trips = result.trips, !trips.isEmpty { print("Driving Route Trips: \(trips[0].duration),\ (trips[0].length)") self.resultsLabel.text = "\(result.status)" } else { self.resultsLabel.text = "No results" } }
Feedback Kit for IOS allows you to integrate feedback module with your apps. Using feedback module user can submit location related feedback to MapmyIndia server.
Note: Sample for UI view controllers with source code is also provided by MapmyIndia which user can directly use to show feedback screen. Information about how to use UI sample is also provided in this documentation.
If you don't want to implement own logic and use sample from MapmyIndia Jump to Sample UI Kit section.
Setup your Project
Usage
Steps to submit feedback:
Report Categories
Categories for reporting can be fetched using get Report Categories method of MapmyIndiaFeedbackKit class by using shared instance.
In response you will receive an error or an array of MapmyIndia Report Categories. Yo will find below useful properties in reportCategories object :
Example
MapmyIndiaFeedbackKit.shared.getReportCategories { (reportCategories, error) in if let error = error { } else { let categories = reportCategories ?? [MapmyIndiaReportCategories]() if categories.count > 0 { print(categories) initWithLatitude:28.630195 longitude:77.218119]]; } else { print("No report categories found") } } }
To submit feedback on MapmyIndia server you can use saveUserData method of MapmyIndiaSaveUserDataAPIManager class by using shared instance. Method save userData will accept an object of MapmyIndiaSaveUserDataOptions class. To initialize MapmyIndiaSaveUserDataOptions user must provide coordinate, parent category, child category, feedback text and Module Id(Optional)
In response of submit feedback either you will receive an error or an result object of type MapmyIndiaUserDataInfo. You will find below useful properties in result object :
let saveOptions = MapmyIndiaSaveUserDataOptions(coordinate: location.coordinate, parentCategory: parentCategory, childCategory: childCategory, description: self.inputTextField.text ?? "", moduleId: self.moduleId) MapmyIndiaSaveUserDataAPIManager.shared.saveUserData(saveOptions, { (savedDataInfo, error) in if let error = error { print(error.localizedDescription) } else if let result = savedDataInfo { print("Feedback submitted: \(result.url ?? "")") } else { print("No results") } })
Setup
Use
To use sample from MapmyIndia use MapmyIndiaFeedbackUIKitManager class. Use share instance of that class and call getViewController method to get default feedback controller and present or push according to requirement.
Note: All functionality of MapmyIndiaFeedbackKit is implemented in default view controller.
Example
CLLocation *location = [[CLLocation alloc] initWithLatitude:_mapView.centerCoordinate.latitude longitude:_mapView.centerCoordinate.longitude]; UINavigationController *navVC = [[MapmyIndiaFeedbackUIKitManager sharedManager] getViewControllerWithLocation:location moduleId:ModuleId]; [self presentViewController:navVC animated:YES completion:nil];
let navVC = MapmyIndiaFeedbackUIKitManager.shared.getViewController(location: CLLocation(latitude: mapView.centerCoordinate.latitude, longitude: mapView.centerCoordinate.longitude), moduleId: ModuleId) self.present(navVC, animated: true, completion: nil)