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 7.1 and above and Xcode 6.0.1 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.
Your MapmyIndia Maps SDK usage needs a set of license keys (get them here) and is governed by the API terms and conditions. As part of the terms and conditions, you cannot remove or hide the MapmyIndia logo and copyright information in your project.
The allowed SDK hits are described on the plans page. Note that your usage is shared between platforms, so the API hits you make from a web application, Android app or an iOS app all add up to your allowed daily limit.
#import <MMIFramework/MMIFramework.h>
[LicenceManager sharedInstance].restAPIKey=your_rest_api_key; [LicenceManager sharedInstance].mapSDKKey=your_java_script_key;
#import <MMIFramework/MMIFramework.h> @interface MapViewController : UIViewController { MMIMapView* mapView; } @end @implementation MapViewController - (void)viewDidLoad { [super viewDidLoad]; mapView = [MMIMapView alloc] initWithFrame:self.view.frame]; [self.view addSubview:mapView]; } @end
//Set zoom to 4 for country level display and 18 for house number display [mapView setZoom:14];
The following function will display user’s current location on the map.
mapView.showUserLocation=YES; NSLog(@"User's location: %@", mapView.userLocation);
The Map object should implement the methods of the MMIDelegate protocol corresponding to the events you wish it to receive. This delegate can also be used to detect map overlays selection. Delegate handles gesture events, tap on annotation (marker), long press on map and map center coordinates.
-(void)mapViewRegionDidChange:(MMIMapView *)mapView; -(void)afterMapMove:(MMIMapView *)map byUser:(BOOL)wasUserAction; -(void)afterMapZoom:(MMIMapView *)map byUser:(BOOL)wasUserAction; -(void)tapOnAnnotation:(MMIAnnotation *)annotation onMap:(MMIMapView *)mapView
To capture single tap on map events, use singleTapOnMap method from MMIDelegate -
- (void)singleTapOnMap:(MMIMapView *)map at:(CGPoint)point;
For long press event, use longPressOnMap method of MMIDelegate -
- (void)longPressOnMap:(MMIMapView *)map at:(CGPoint)point;
Add a Marker
To add a marker, create a MMIAnnotation object that includes a location, title/subtitle and markerImage etc.
MMIAnnotation* annotation=[[MMIAnnotation alloc] init]; annotation.latitude=28.526; annotation.longitude=78.568; annotation.title=@"Delhi" ; //the title is shown in the info window as described below [mapView addAnnotation:annotation];
Remove a Marker
[mapView removeAnnotation:annotation]; // to remove a single marker [mapView removeAllAnnotations]; // to clear all markers on map
Change default marker icon
annotation.markerImage=[UIImage imageNamed:@"placemarker.png"]; //formats supported - png,jpg annotation.makerSize=CGSizeMake(48, 48); //set any size that looks good with your image
Marker Opacity
MMIAnnotation* annotation=[[MMIAnnotation alloc] init]; annotation.latitude=28.123 annotation.longitude=78.563 annotation.opacity=0.5; [mapView addAnnotation:annotation];
Enable display of info windows on annotation tap event.
MMIAnnotation* annotation=[[MMIAnnotation alloc] init]; annotation.latitude=28.123 annotation.longitude=78.563 annotation.title=@"Welcome"; annotation.canShowCallout=YES; annotation.opacity=1.0;
To enable auto-clustering on all markers displayed on map, set the value to True. Default is False. See marker clustering in action in the samples bundled in the SDK.
mapView.clusteringEnabled=NO;
Add a Polyline
NSArray *locations = [NSArray arrayWithObjects: [[CLLocation alloc] initWithLatitude:28.54937553 longitude:77.26795197], [[CLLocation alloc] initWithLatitude:28.54939461 longitude:77.26816559], [[CLLocation alloc] initWithLatitude:28.54946899 longitude:77.26811981], [[CLLocation alloc] initWithLatitude:28.54972458 longitude:77.26800537],nil]; [mapView drawPolyLine:locations];
Remove a Polyline
[mapView removePolyLine];
Customize a Polyline
Change width of polyline -
mapView.polylineWidth=4.0;
Change color of polyline –
mapView.polylineColor=[UIColor greenColor];
Add a Polygon
NSMutableArray* polygonVertices = [[NSMutableArray alloc] initWithCapacity:50]; CLLocation* location1=[[CLLocation alloc] initWithLatitude:26.613434longitude:75.758556]; CLLocation* location2=[[CLLocation alloc] initWithLatitude:26.311922longitude:76.492635]; CLLocation* location3=[[CLLocation alloc] initWithLatitude:26.230916longitude:76.130366]; CLLocation* location4=[[CLLocation alloc] initWithLatitude:26.364601longitude:75.832132]; CLLocation* location5=[[CLLocation alloc] initWithLatitude:26.613434longitude:75.758556]; [polygonVertices addObject:location1]; [polygonVertices addObject:location2]; [polygonVertices addObject:location3]; [polygonVertices addObject:location4]; [polygonVertices addObject:location5]; [mapViewdrawPolyLine:polygonVertices];
Add a Circle
You must specify the following parameters to add a circle on the map –
MMIAnnotation* annotation=[[MMIAnnotationalloc] init]; annotation.latitude=28.526; annotation.longitude=78.568; annotation.radiusInMeters=500; annotation.lineWidthInPixels=5;
annotation.lineColor=[UIColor redColor]; //change the stroke color of the circle annotation.fillColor=[UIColor colorWithRed:.5 green:.466 blue:.733 alpha:.25]; //change the fill color of the circle
The following search services are available as part of the SDK bundled by default (Make sure you include following import in your code) –
#import <MMIFramework/MMIFramework.h>
You can read more on MapmyIndia's Geocoding API. To geocode an address, create an instance of GeocodeManager class and call the getPlace method –
GeocodeManager *managerObject = [[GeocodeManager alloc] init]; [managerObject getPlace:@“New Delhi” completion:^(NSDictionary *result,NSError* error){ // if error is nil, then result is success. // response includes responseCode,version and results Array }];
You can find address for a point on the map by using the MapmyIndia Maps Reverse Geocoding API. Pass the GeoPoint to the ReverseGeocodeManager class –
ReverseGeocodeManager *reverseGeoCodeManagerObject=[[ReverseGeocodeManager alloc]init]; [reverseGeoCodeManagerObject getPlace:CLLocationCoordinate2DMake(startPoint, finalPoint) completion:^(NSDictionary *result,NSError* error){ // if error is nil, then result is success. // response is the results array }];
adasdas
MapmyIndia Beacon SDK is primarily used for developing location-aware applications. This will help the user to review where your device has been.
Location send frequency in the Beacon SDK depends on the selected profile.
3 different pre-defined profiles are :
Please note, use of the profiles depends upon the desired requirement. For example if distance needs to be measured, then suggested profile is vehicle. Although due to frequent GPS and GPRS use, battery of the device may drain out quicker in vehicle profile.
It is recommended that you use Android Studio as your IDE for development. MapmyIndia Beacon SDK for Android supports Android API version 10 and above. You can send location information from your app by using the MapmyIndia Beacon SDK. The SDK provides control features in terms starting and stopping the Beacon service.
MapmyIndia Intouch API key can be obtained from your API dashboard. This key will enable you to access different components of Beacon SDK.
Note : Beacon SDK will work on those devices which have GSM module i.e a valid IMEI number.
Currently if the location module of the device is not able to get any location from GPS or Cell network then no position is reported from the device.
Your MapmyIndia Beacon SDK usage needs a set of license keys and is governed by the API terms and conditions.
Setup your project:<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
and following in application tag
<service android:name="com.mmi.beacon.service.BeaconTrackerService"/> <receiver android:name="com.mmi.beacon.receiver.NetworkChangeReceiver" /> <intent-filter/> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <action android:name="com.mmi.beacon.LOGGER"/> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> <intent-filter/> <receiver/>
Add your API keys to the SDK
Make the following function calls in the Application Class -
LicenceManager.getInstance().setMapmyIndiaBeaconToken(Your_token);
public class DemoApplication extends Application { @Override public void onCreate() { super.onCreate(); LicenceManager.getInstance().setMapmyIndiaBeaconToken(Your_token); } }
Note: You should not use the MapmyIndia Beacon SDK without these function calls. You will find your keys in your API Dashboard.
Class: MapmyIndiaBeacon
Steps to integrate:
1. Need to register device with “RegisterDeviceListener”
MapmyIndiaBeacon.getInstance(getActivity()).registerDevice(resultCode,deviceName,listener);
On successful registration you will receive a callback in “onRegistration(trackingCode)”.
If registration is failed,
“public void onError(int resultCode, int errorCode, String message)” will be called.
“resultCode” is same what you pass while calling “registerDevice”.
List of “errorCode”
public static int INTERNET_ERROR = 1001; public static int INVALID_TOKEN_ERROR = 1002; public static int DEVICE_NOT_FOUND_ERROR = 1003; public static int OTHER_ERROR = 1004;
List of “message” for errors.
public static String MSG_INVALID_TOKEN_ERROR = "Invalid token"; public static String MSG_OTHER_ERROR = "Something went wrong";
2. Once successful, user can call “startBeacon” function as follows
MapmyIndiaBeacon.getInstance(getActivity()).startBeacon(MapmyIndiaBeacon.TrackingProfile.PEOPLE);
MapmyIndiaBeacon.TrackingProfile.PEOPLE MapmyIndiaBeacon.TrackingProfile.HYBRID MapmyIndiaBeacon.TrackingProfile.VEHICLE
MapmyIndiaBeacon.getInstance(getActivity()).stopBeacon();