iOS SDKs

Easy integration on your iOS displaying raster map tiles to make location aware applications for a much larger reach

MapmyIndia Map iOS SDK

Getting Started

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.

API Usage

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.

Setup your project

  • Create a new project in Xcode
  • Drag and drop the MapmyIndiaAPIKit Framework to your project. It must be added in embedded binaries.
  • Drag and drop the MapmyIndia Map SDK framework (MMIFramework.framework) and resource bundle file (MMIFramework.bundle) to your project
  • Add these dependencies to your project (Build Phases > Link Binary with Libraries) -
    • libsqlite3.0.dylib
    • libz.dylib
  • Add compiler flag (Project target > Build Settings > Other Linker Flags > Set `-ObjC`)
  • For iOS8 or later, make this change to your info.plist (Project target > info.plist > Add row and set key `NSLocationWhenInUseUsageDescription`)
  • Add your MapmyIndia Map API keys to your AppDelegate.m as follows-
      1. Add the following import statement
        #import <MMIFramework/MMIFramework.h>
      2. Add the following to your application:didFinishLaunchingWithOptions: method, replacing restAPIKey and mapSDKKey with your own API keys:
        [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.

Add a MapmyIndia Map

#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

Map Interactions

Set Zoom Level

//Set zoom to 4 for country level display and 18 for house number display
[mapView setZoom:14];

Current Location

The following function will display user’s current location on the map.

mapView.showUserLocation=YES;

NSLog(@"User's location: %@", mapView.userLocation);

Map Events

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

Map Tap/Long Press

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;

Map Overlays

Markers

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];

Info Windows

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;

Marker Clustering

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;

Polylines

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];

Polygons

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];

Circles

Add a Circle
You must specify the following parameters to add a circle on the map –

  • position (latitude, longitude)
  • radiusInMeters (in meters)
  • lineWidthInPixels (width of circle stroke)
MMIAnnotation* annotation=[[MMIAnnotationalloc] init];
annotation.latitude=28.526;
annotation.longitude=78.568;
annotation.radiusInMeters=500; 
annotation.lineWidthInPixels=5;
Customize a Circle
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
Search

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>

Geocoding

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   
 
}];

Reverse Geocoding

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      
}];

Routes & Navigation

Routing API

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 
}];

Driving Distance Matrix API

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
}];

REST APIs

Autosuggest

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

  1. location: Location is required to get location bias autosuggest results.
  2. zoom: takes the zoom level of the current scope of the map (min: 4, max: 18).
  3. includeTokenizeAddress: On setting value of this property to true it provides the different address attributes in a structured object in response.
  4. pod: It takes place type which helps in restricting the results to certain chosen type
    Below mentioned are the codes for the pod -
    • Sublocality
    • Locality
    • City
    • Village
    • Subdistrict
    • District
    • State
    • Subsublocality
  5. filter: this helps you restrict the result either by mentioning a bounded area or to certain eLoc. Below mentioned are the both types whose instance can be set to this parameter -
    • (a) MapmyIndiaElocFilter: to filter results on basis of eLoc
    • (b) MapmyIndiaBoundsFilter: to filter results on basis of geo bound.

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 :

  1. type: type of location POI or Country or City
  2. eLoc: Place Id of the location 6-char alphanumeric.
  3. placeAddress: Address of the location.
  4. latitude: Latitude of the location.
  5. longitude: longitude of the location.
  6. entranceLatitude: entry latitude of the location
  7. entrancelongitude: entry longitude of the location
  8. placeName: Name of the location.
  9. orderIndex: the order where this result should be placed
  10. addressTokens:
    • houseNumber: house number of the location.
    • houseName: house name of the location.
    • poi: name of the POI (if applicable)
    • street: name of the street. (if applicable)
    • subSubLocality: the sub-sub-locality to which the location belongs. (if applicable)
    • subLocality: the sub-locality to which the location belongs. (if applicable)
    • locality: the locality to which the location belongs. (if applicable)
    • village: the village to which the location belongs. (if applicable)
    • subDistrict: the sub-district to which the location belongs. (if applicable)
    • district: the district to which the location belongs. (if applicable)
    • city: the city to which the location belongs. (if applicable)
    • state: the state to which the location belongs. (if applicable)
    • pincode: the PIN code to which the location belongs. (if applicable)

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"

Geocoding (Forward Geocode)

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:

  • eLoc: The 6-digit alphanumeric code for any location. (e.g. mmi000).
  • address: The address of a location (e.g. 237 Okhla Phase-III).
  • POI: The name of the location (e.g. MapmyIndia Head Office).
  • House Number: The house number of the location in case full address is unknown (e.g. P- 18/114).

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 :

  • houseNumber: The house number of the location.
  • houseName: The name of the location.
  • poi: The name of the POI if the location is a place of interest (POI).
  • street: The name of the street of the location.
  • subSubLocality: The name of the sub-sub-locality where the location exists.
  • subLocality: The name of the sub-locality where the location exists.
  • locality: The name of the locality where the location exists.
  • village: The name of the village if the location exists in a village.
  • district: The name of the district in which the location exists.
  • subDistrict: The name of the sub-district in which the location exists.
  • city: The name of the city in which the location exists.
  • state: The name of the state in which the location exists.
  • pincode: The pin code of the location area.
  • latitude: The latitude of the location.
  • longitude: The longitude of the location.
  • formattedAddress: The complete human readable address string that is usually the complete postal address of the result.
  • placeId: The eLoc or placeId assigned for a place in map database. An eLoc is the digital identity for an address or business to identify its unique location. For more information on eLoc, click here.
  • type: defines the type of location matched (HOUSE_NUMBER, HOUSE_NAME, POI, STREET, SUB_LOCALITY, LOCALITY, VILLAGE, DISTRICT, SUB_DISTRICT, CITY, STATE, SUBSUBLOCALITY, PINCODE).

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"
}
}

Reverse Geocoding

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 :

  • houseNumber: The house number of the location.
  • houseName: The name of the location.
  • poi: The name of the POI if the location is a place of interest (POI).
  • poiDist: distance from nearest POI in metres.
  • street: The name of the street of the location.
  • streetDist: distance from nearest Street in metres.
  • subSubLocality: The name of the sub-sub-locality where the location exists.
  • subLocality: The name of the sub-locality where the location exists.
  • locality: The name of the locality where the location exists.
  • village: The name of the village if the location exists in a village.
  • district: The name of the district in which the location exists.
  • subDistrict: The name of the sub-district in which the location exists.
  • city: The name of the city in which the location exists.
  • state: The name of the state in which the location exists.
  • pincode: The pin code of the location area.
  • latitude: The latitude of the location.
  • longitude: The longitude of the location.
  • formattedAddress: The complete human readable address string that is usually the complete postal address of the result.
  • area: in-case the co-ordinate lies in a country the name of the country would be returned or if the co-ordinate lies in an ocean, the name of the ocean will be returned.

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

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

  • 1. page: provides number of the page to provide results from.
  • 2. sort: provides configured sorting operations for the client on cloud. Below are the available sorts:
  • a) dist:asc & dist:desc - will sort data in order of distance from the passed location (default).
  • b) name:asc & name:desc - will sort the data on alphabetically bases.
  • 3. radius (integer): provides the range of distance to search over (default: 1000, min: 500, max: 10000).
  • 4. bounds (x1,y1;x2,y2): Allows the developer to send in map bounds to provide a nearby search of the geobounds. where x1,y1 are the latitude and langitude.

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 :

  • distance: provides the distance from the provided location bias in meters.
  • eLoc: Place Id of the location 6-char alphanumeric.
  • email: Email for contact.
  • entryLatitude: latitude of the entrance of the location.
  • entryLongitude: longitude of the entrance of the location.
  • keywords: provides an array of matched keywords or codes.
  • landlineNo: Email for contact.
  • latitude: Latitude of the location.
  • longitude: longitude of the location.
  • mobileNo : Phone number for contact.
  • orderIndex: the order where this result should be placed
  • placeAddress: Address of the location.
  • placeName: Name of the location.
  • type: Type of location POI or Country or City.?

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"
			}
}

eLoc / Place Details

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 :

  • houseNumber: The house number of the location.
  • houseName: The name of the location.
  • poi: The name of the POI if the location is a place of interest (POI).
  • street: The name of the street of the location.
  • subSubLocality: The name of the sub-sub-locality where the location exists.
  • subLocality: The name of the sub-locality where the location exists.
  • locality: The name of the locality where the location exists.
  • village: The name of the village if the location exists in a village.
  • district: The name of the district in which the location exists.
  • subDistrict: The name of the sub-district in which the location exists.
  • city: The name of the city in which the location exists.
  • state: The name of the state in which the location exists.
  • pincode: The pin code of the location area.
  • latitude: The latitude of the location.
  • longitude: The longitude of the location.
  • placeId: The eLoc or placeId assigned for a place in map database. An eLoc is the digital identity for an address or business to identify its unique location. For more information on eLoc, click here
  • type: defines the type of location matched (HOUSE_NUMBER, HOUSE_NAME, POI, STREET, SUB_LOCALITY, LOCALITY, VILLAGE, DISTRICT, SUB_DISTRICT, CITY, STATE, SUBSUBLOCALITY, PINCODE)

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"
}
}

Driving Distance

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 :

  • 1. routeType: It is type of enum DistanceRouteType.
  • 2. vehicleType: It is type of enum DistanceVehicleType.
  • 3. avoids: The parameter to avoid road types along the route with default value none. It is type of enum DistanceAvoidsType.
  • 4. withTraffic: The parameter is to check distance along the traffic with default value false. To get distance with traffic pass true.

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 :

  • duration: Duration of route in seconds.
  • status: Status set by routing engine: 6 means OK, any other number represents specific routing error.
  • length: Length of route in meters.

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"
  	}
}

Routing

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.

  • 1. viaPoints: the optional list of via-points. The complete route will therefore be start . via points in provided order . destination Note: "Maximum of 16 via points can be added." Also, look at the pricing section to know about the pricing and deductions for the use of via points in the API.
  • 2. routeType: It is type of enum DistanceRouteType.
  • 3. vehicleType: It is type of enum DistanceVehicleType.
  • 4. avoids: The parameter to avoid road types along the route with default value none. It is type of enum DistanceAvoidsType.
  • 5. withAlternatives: (true or false) : Parameter to toggle alternative routes. If .true. is sent, alternative routes will be provided else not. By default, the value is false. So, if the parameter is not sent, no alternative routes will be provided.
  • 6. withAdvices: Advices are turn by turn navigation guidance provided by MapmyIndia routing services (e.g. After 200m take the first exit from the roundabout). To get advices send value true else send false.

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 :

  • 1 Status :
    • a. Success:
      • i) 0 for OK
    • b. Error:
      • i) 1 for too few waypoints provided]
      • ii) 2 for system error, route calculation failed.
  • 2. trips: A collection of routes that contain an object with the following properties:
    • duration: Duration of the route in seconds.
    • status: Status set by routing engine: 6 means OK, any other number represents specific routing error. (Number)
    • length: Length of the entire trip in meters.
    • pts: string of WGS-84 longitude-latitude pairs that indicates the path that needs to be drawn on the map to indicate the computed route. Please see notes below.
    • advices (object): An array of advice objects. An advice is the instruction for the end user that often appears at critical points along a route. Each advice object consists of:
      • text: Description of the advice.
      • iconId: The numeric id of the icon that represents current advice icon. For details refer to Appendix C.
      • meters: Distance to the advice location from the start point.
      • seconds: Time to reach to the advice location from the start point.
      • exitNR: The exit number on roundabout exit, 0 if advice is not on roundabout manoeuvre.
      • point: an object of latitude and longitude of the location of the advice.
        • longitude: longitude of the advice position.
        • latitude: latitude of the advice position
  • 5. viaPoints: A collection of alternative routes if the alternatives parameter is provided and is set to true else null is returned.

Note:

  • In case Via-Points are provided, no alternative routes will be returned.
  • If Via Points are provided then each via point is considered as a single trip hence you.ll receive a collection of trips object with 1 item if no via point is added and more if via points are added.
  • The Data type is the same as that of the trip object
  • pts string needs to decode and convert into array of coordinates to be used on application side. A library to achieve this can be found here. Where precision 1e6 should be passed to decode.

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

Getting Started

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

  • Create a new project in Xcode.
  • Drag and drop the MapmyIndiaFeedbackKit SDK Framework (MapmyIndiaFeedbackKit.framework) to your project. It must be added in embedded binaries.

Usage

Steps to submit feedback:

  1. User must have a module Id(provided by MapmyIndia) for which feedback will be submitted.
  2. Then user must have some coordinate for which feedback will be submitted, value of coordinate can be a constant or dynamic variable as per user requirement.
  3. Now user have to get categories i.e Report Categories under which feedback will be submitted.
  4. User can save this fetched report categories for offline use or to prevent fetching report categories multiple times.
  5. After getting report categories from step 3 user have to separate out them on basis of parentId i.e Separate as Parent and Child Categories, where if parent Id is null means they are parent categories otherwise child of some parent category. Note: ParentId of a child category is reportId of parent category.
  6. Now create some scenario for selecting parent category and child category(as per selected parent category).
  7. After selecting of parent and child category user must take some input as a text for feedback.
  8. Now user can submit feedback using MapmyIndia Kit.s helper methods by providing collected data from previous steps i.e Module Id, Coordinate, Parent Category, Child Category and Feedback Text Description.

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

  • reportId: Unique Identifier.
  • reportName: The name of category to display .
  • parentId: Parent Id for report category.
  • created: Timestamp
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")
				}
		}	
	}

Submit Feedback

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 :

  • dataCount: Count in how much list it exists.
  • name: The name of item.
  • exist: Integer value which tells is result exist on server.
  • id: Unique Identifier.
  • listId: Id of list in which it exists.
  • time: Timestamp.
  • url: URL for reported item.

Example

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")
		}
})

Sample UI Kit

Setup

  • Create a new target Cocoa Touch Framework in your existing project in Xcode.
  • Name that target to MapmyIndiaFeedbackUIKit.
  • Copy all resource files from sample project MapmyIndiaFeedbackUIKit.
  • Drag and drop the MapmyIndiaFeedbackKit SDK Framework (MapmyIndiaFeedbackKit.framework) in embedded binaries section of your newly created target MapmyIndiaFeedbackUIKit.
  • Add reference of this newly created target into your application project.

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)