iOS SDKs

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

MapmyIndia Vector Map iOS SDK

Getting Started

MapmyIndia Maps SDK for IOS lets you easily add MapmyIndia Maps and web services to your own iOS app. MapmyIndia Maps SDK for iOS supports iOS SDK 9.0 and above and Xcode 9 or later. You can have a look at the map and features you will get in your own app by using the MapmyIndia Maps app for iOS. The SDK handles map tiles download and their display along with a bunch of controls and native gestures.

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 MapmyIndia Map SDK Framework (Mapbox.framework) to your project. It must be added in embedded binaries.
  • Drag and drop the MapmyIndiaAPIKit Framework to your project. It must be added in embedded binaries. It is a dependent framework.
  • In the Build Phases tab of the project editor, click the + button at the top and select .New Run Script Phase.. Enter the following code into the script text field: bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/ Mapbox.framework/strip-frameworks.sh"
  • For iOS9 or later, make this change to your
    info.plist (Project target > info.plist > Add row and set key `NSLocationWhenInUseUsageDescription`,
    `NSLocationAlwaysUsageDescription`)

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 map view

Map View on view controller can be added either using interface builder or programmatically.

By Interface Builder :-
In a storyboard, add a view to your View Controller. In the Identity inspector, change its class to MapmyIndiaMapView.
Note :- Map style url need to be set at the time of load map

By Programmatically :-
To add map on view Controller create an instance of .MGLMapView. and add this to view of ViewController.

#import 
@interface ViewController () <MGLMapViewDelegate>
@end
@implementation ViewController
import Mapbox
  class ViewController: UIViewController, MGLMapViewDelegate {
  override func viewDidLoad() {
  super.viewDidLoad()
  let mapView = MapmyIndiaMapView(frame: view.bounds)
  mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  view.addSubview(mapView)
            }
     });

Note :- Also add app transport security exception in Info.plist of your project

Example NSAppTransportSecurity NSAllowsArbitraryLoads

Map Interactions :-

Set Zoom Level :-

Set zoom to 4 for country level display and 18 for house number display.

mapView.zoomLevel = 4;
mapView.zoomLevel = 4

Current Location :-

mapView.showsUserLocation = YES;
self.mapView.showsUserLocation = true

Map Features

User Location

Show user location

To show user location on map use property .showsUserLocation. and set its value to true.

mapView.showsUserLocation = true

Tracking Mode

To move map with user location change use property userTrackingMode. Its an enum property of type .MGLUserTrackingMode.. You can set any value from follow, followWithCourse, followWithHeading, none

mapView.userTrackingMode = .followWithCourse

Map Events

The Map object should implement the methods of the MGLMapViewDelegate 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) and map center coordinates.

Map Position Changes Events

- (BOOL)mapView:(MGLMapView *)mapView shouldChangeFromCamera:(MGLMapCamera
*)oldCamera toCamera:(MGLMapCamera *)newCamera;
- (BOOL)mapView:(MGLMapView *)mapView shouldChangeFromCamera:(MGLMapCamera
*)oldCamera toCamera:(MGLMapCamera *)newCamera reason:
(MGLCameraChangeReason)reason;
- (void)mapView:(MGLMapView *)mapView regionWillChangeAnimated:
(BOOL)animated;
- (void)mapView:(MGLMapView *)mapView regionWillChangeWithReason:
(MGLCameraChangeReason)reason animated:(BOOL)animated;
- (void)mapViewRegionIsChanging:(MGLMapView *)mapView;
- (void)mapView:(MGLMapView *)mapView regionIsChangingWithReason:
(MGLCameraChangeReason)reason;
- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:
(BOOL)animated;
- (void)mapView:(MGLMapView *)mapView regionDidChangeWithReason:
(MGLCameraChangeReason)reason animated:(BOOL)animated;

Loading the Map Events

- (void)mapViewWillStartLoadingMap:(MGLMapView *)mapView;
- (void)mapViewDidFinishLoadingMap:(MGLMapView *)mapView;
- (void)mapViewDidFailLoadingMap:(MGLMapView *)mapView withError:(NSError
*)error;
- (void)mapViewWillStartRenderingMap:(MGLMapView *)mapView;
- (void)mapViewWillStartRenderingFrame:(MGLMapView *)mapView;
- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:
(BOOL)fullyRendered;
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle
*)style;

Tracking User Location Events

- (void)mapViewWillStartLocatingUser:(MGLMapView *)mapView;
- (void)mapViewDidStopLocatingUser:(MGLMapView *)mapView;
- (void)mapView:(MGLMapView *)mapView didUpdateUserLocation:(nullable
MGLUserLocation *)userLocation;
- (void)mapView:(MGLMapView *)mapView didFailToLocateUserWithError:(NSError
*)error;
- (void)mapView:(MGLMapView *)mapView didChangeUserTrackingMode:
(MGLUserTrackingMode)mode animated:(BOOL)animated;

Appearance of Annotations Events

- (nullable MGLAnnotationImage *)mapView:(MGLMapView *)mapView
imageForAnnotation:(id <MGLAnnotation>)annotation;
- (CGFloat)mapView:(MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape
*)annotation;
- (UIColor *)mapView:(MGLMapView *)mapView strokeColorForShapeAnnotation:
(MGLShape *)annotation;
- (UIColor *)mapView:(MGLMapView *)mapView fillColorForPolygonAnnotation:
(MGLPolygon *)annotation;
- (CGFloat)mapView:(MGLMapView *)mapView lineWidthForPolylineAnnotation:
(MGLPolyline *)annotation;

Annotation Views Events

- (nullable MGLAnnotationView *)mapView:(MGLMapView *)mapView
viewForAnnotation:(id <MGLAnnotation>)annotation;
- (void)mapView:(MGLMapView *)mapView didAddAnnotationViews:
(NS_ARRAY_OF(MGLAnnotationView *) *)annotationViews;

Selecting Annotations Events

- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id
<MGLAnnotation>)annotation;
- (void)mapView:(MGLMapView *)mapView didDeselectAnnotation:(id
<MGLAnnotation>)annotation;
- (void)mapView:(MGLMapView *)mapView didSelectAnnotationView:
(MGLAnnotationView *)annotationView;
- (void)mapView:(MGLMapView *)mapView didDeselectAnnotationView:
(MGLAnnotationView *)annotationView;

Callout Views Events

- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id
<MGLAnnotation>)annotation;
- (nullable id <MGLAnnotation>)mapView:(MGLMapView *)mapView
calloutViewForAnnotation:(id <MGLAnnotation>)annotation;
- (nullable UIView *)mapView:(MGLMapView *)mapView
leftCalloutAccessoryViewForAnnotation:(id <MGLAnnotation>)annotation;
- (nullable UIView *)mapView:(MGLMapView *)mapView
rightCalloutAccessoryViewForAnnotation:(id <MGLAnnotation>)annotation;
- (void)mapView:(MGLMapView *)mapView annotation:(id
<MGLAnnotation>)annotation calloutAccessoryControlTapped:(UIControl
*)control;
- (void)mapView:(MGLMapView *)mapView tapOnCalloutForAnnotation:(id
<MGLAnnotation>)annotation;

Map Tap/Long

To capture single tap on map events add a tap gesture to instance of MGLMapView.

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(didTapPress:)];
[self.mapView addGestureRecognizer:singleTap];

- (void)didTapPress:(UILongPressGestureRecognizer *)gesture {
if(UIGestureRecognizerStateEnded == gesture.state) {
//Do Whatever You want on End of Gesture
   }
  }						
let singleTap = UITapGestureRecognizer(target: self, action:
 #selector(didTapMap(tap:)))
 mapView.addGestureRecognizer(singleTap)
 @objc func didTapMap(tap: UITapGestureRecognizer) {
 if tap.state == .ended {
   //Do Whatever You want on End of Gesture
  }
}

To capture long press on map events add a long press gesture to instance ofMGLMapView.

UILongPressGestureRecognizer *longPress =  [[UILongPressGestureRecognizer
alloc] initWithTarget:self action:@selector(didLongPress:)];
[longPress setMinimumPressDuration:1.0];
[self.mapView addGestureRecognizer:longPress];
- (void)didLongPress:(UILongPressGestureRecognizer *)gesture {
if(UIGestureRecognizerStateEnded == gesture.state) {
//Do Whatever You want on End of Gesture
   }
  }					
let longPress = UILongPressGestureRecognizer(target: self, action:
#selector(didLongPress(tap:)))
mapView.addGestureRecognizer(longPress)
@objc func didLongPress(tap: UILongPressGestureRecognizer) {
if tap.state == .began {
//Do Whatever You want on End of Gesture
  }
}

Map Overlays

Markers

Add a marker

To show an annotation on map create an instance of MGLPointAnnotation and add that object to instance of MGLMapView using method .addAnnotation..

After creating instance of MGLPointAnnotation set coordinate and title property values.

Example

MGLPointAnnotation *point = [[MGLPointAnnotation alloc] init];
point.coordinate = CLLocationCoordinate2DMake(28.550834, 77.268918);
point.title = @"Annotation";
[self.mapView addAnnotation:point];
 var point = MGLPointAnnotation()
point.coordinate = CLLocationCoordinate2D(latitude: 28.550834, longitude:
77.268918)
point.title = "Annotation"
mapView.addAnnotation(point)

Remove a marker

Example

MGLPointAnnotation *point = [[MGLPointAnnotation alloc] init];
point.coordinate = CLLocationCoordinate2DMake(28.550834, 77.268918);
point.title = @"Annotation";
[self.mapView addAnnotation:point];
 var point = MGLPointAnnotation()
point.coordinate = CLLocationCoordinate2D(latitude: 28.550834, longitude:
77.268918)
point.title = "Annotation"
mapView.addAnnotation(point)

Change default marker icon

To change image for default marker you can use delegate methods of protocol
MGLMapViewDelegate.
Either you can override whole view of marker by using below method of delegate:

 - (nullable MGLAnnotationView *)mapView:(MGLMapView *)mapView
viewForAnnotation:(id <MGLAnnotation>)annotation;

or you can override image of marker by using below method of delegate:

- (nullable MGLAnnotationImage *)mapView:(MGLMapView *)mapView
imageForAnnotation:(id <MGLAnnotation>)annotation;

Info Windows

To enable info window on tap of marker return true from below delegate method:

- (BOOL)mapView:(MGLMapView *)mapView 
annotationCanShowCallout:(id <MGLAnnotation>)annotation;

Change default info window (callout)

To change default callout view of annotation use delegate function of .MGLMapViewDelegate. protocol and return custom view of callout from that

function.

func mapView(_ mapView: MGLMapView, calloutViewFor annotation:
MGLAnnotation) -> MGLCalloutView? {
return CustomCalloutView(representedObject: annotation)
}

To create custom callout view create a class inherited from .MGLCalloutView. and .UIView.. Override draw function of UIView to design your own callout view.

Polylines

Add a Polyline

To show a polyline on map create an instance of MGLPolyline and add that object to instance of MGLMapView using method .addAnnotation..

To create instance of MGLPolyline an array of CLLocationCoordinate2D will be required so first create an array of CLLocationCoordinate2D.

Example

CLLocationCoordinate2D coordinates[] = {
CLLocationCoordinate2DMake(28.550834, 77.268918),
CLLocationCoordinate2DMake(28.551059, 77.268890),
CLLocationCoordinate2DMake(28.550938, 77.267641),
CLLocationCoordinate2DMake(28.551764, 77.267575),
CLLocationCoordinate2DMake(28.552068, 77.267599),
CLLocationCoordinate2DMake(28.553836, 77.267450),
};

NSUInteger numberOfCoordinates = sizeof(coordinates) / sizeof(CLLocationCoordinate2D);

MGLPolyline *polyline = [MGLPolyline polylineWithCoordinates:coordinates
count:numberOfCoordinates];//

[self.mapView addAnnotation:polyline];
var coordinates = [
CLLocationCoordinate2D(latitude: 28.550834, longitude: 77.268918),
CLLocationCoordinate2D(latitude: 28.551059, longitude: 77.268890),
CLLocationCoordinate2D(latitude: 28.550938, longitude: 77.267641),
CLLocationCoordinate2D(latitude: 28.551764, longitude: 77.267575),
CLLocationCoordinate2D(latitude: 28.552068, longitude: 77.267599),
CLLocationCoordinate2D(latitude: 28.553836, longitude: 77.267450),
]
let polyline = MGLPolyline(coordinates: &coordinates, count: UInt(coordinates.count))
mapView.addAnnotation(polyline)

Remove a Polyline

[self.mapView removeAnnotation:polyline]
mapView.removeAnnotation(polyline))

Polygons


Add a Polygon

To show a polygon on map create an instance of MGLPolygon and add that object to instance of MGLMapView using method .addAnnotation..

To create instance of MGLPolygon an array of CLLocationCoordinate2D will be required so first create an array of CLLocationCoordinate2D.

Example

CLLocationCoordinate2D coordinates[] = {
CLLocationCoordinate2DMake(28.550834, 77.268918),
CLLocationCoordinate2DMake(28.551059, 77.268890),
CLLocationCoordinate2DMake(28.550938, 77.267641),
CLLocationCoordinate2DMake(28.551764, 77.267575),
CLLocationCoordinate2DMake(28.552068, 77.267599),
CLLocationCoordinate2DMake(28.553836, 77.267450),
};
NSUInteger numberOfCoordinates = sizeof(coordinates) /
sizeof(CLLocationCoordinate2D);
MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:coordinates
count:numberOfCoordinates];//
[self.mapView addAnnotation:polygon];
var coordinates = [
CLLocationCoordinate2D(latitude: 28.550834, longitude:
77.268918),
CLLocationCoordinate2D(latitude: 28.551059, longitude:
77.268890),
CLLocationCoordinate2D(latitude: 28.550938, longitude:
77.267641),
CLLocationCoordinate2D(latitude: 28.551764, longitude:
77.267575),
CLLocationCoordinate2D(latitude: 28.552068, longitude:
77.267599),
CLLocationCoordinate2D(latitude: 28.553836, longitude:
77.267450),
]
let polygon = MGLPolygon(coordinates: &coordinates, count:
UInt(coordinates.count))
mapView.addAnnotation(polygon)

Remove a Polygon

Example

[self.mapView removeAnnotation:polygon]
mapView.removeAnnotation(polygon)

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)