Call at MapmyIndia
Product release

Personalisation SDK, by MapmyIndia, is India's first O2O engagement tool that can 3X your customer engagement, retention and conversion.

or

android SDKs

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

MapmyIndia Map Android SDK

Getting Started

MapmyIndia.s Android Map SDK helps to embed MapmyIndia maps within your Android 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

Follow these steps to add the SDK to your project –

  • Create a new project in Android Studio
  • Copy the SDK jar file to project libs/ folder
  • Add the following permissions to your AndroidManifest.xml file
  • Add Gson library to your project: "compile 'com.google.code.gson:gson:2.3'"
<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" />
  • Add your API keys to the SDK
Make the following function calls in the Application Class -
The grant type is "client_credentials" (without quotes).
MapmyIndiaAccountManager.getInstance().setRestAPIKey(getRestAPIKey());
MapmyIndiaAccountManager.getInstance().setMapSDKKey(getMapSDKKey()); 
MapmyIndiaAccountManager.getInstance().setAtlasGrantType(getAtlasGrantType());
MapmyIndiaAccountManager.getInstance().setAtlasClientId(getAtlasClientId());
MapmyIndiaAccountManager.getInstance().setAtlasClientSecret(getAtlasClientSecret());
public class DemoApplication extends Application {

   @Override
   public void onCreate() {
       super.onCreate();
       LicenceManager.getInstance().setRestAPIKey("your_rest_api_key");
       LicenceManager.getInstance().setMapSDKKey("your_java_script_key");
   }
}
You cannot use the MapmyIndia Map Mobile SDK without these function calls. You will find your keys in your API Dashboard.

Add a MapmyIndia Map to your application

Follow these steps to load a MapmyIndia Map in your project –

  • Layout
    Create main.xml layout as res/layout/main.xml so it has com.mmi.MapmyIndiaMapView element:
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent">
<com.mmi.MapmyIndiaMapView
android:id="@+id/map" 
android:layout_width="match_parent" 
android:layout_height="match_parent" />
</LinearLayout>
  • Create the main activity (MainActivity.java):
public class MainActivity extends Activity {

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
//Add a Map View to your XML layout
       MapmyIndiaMapView  mapMyIndiaMapView = (MapmyIndiaMapView)  findViewById(R.id.map);
        MapView mMapView = mapMyIndiaMapView.getMapView();


      //if you want to create map view Instance D dynamically 
       MapmyIndiaMapView  mapMyIndiaMapView = new MapmyIndiaMapView (this);
       MapView mMapView = mapMyIndiaMapView.getMapView();
 setContentView(mapMyIndiaMapView);
    }

}

If you want to use MapView with Fragment, use the following

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//Dynamically
MapmyIndiaMapView mapmyIndiaMapView=new MapmyIndiaMapView(inflater.getContext());

MapView mMapView =mapmyIndiaMapView.getMapView();

return mapmyIndiaMapView;

//from layout

View view = inflater.inflate(R.layout.mapview, container, false);
MapView mMapView = ((MapmyIndiaMapView) view.findViewById(R.id.mapview)).getMapView();
return view;
}
  • Set Map Center
GeoPoint geoPoint= new GeoPoint(48.8583, 22.944);
mMapView.setCenter(geoPoint);

Map Interactions

The MapmyIndia Maps Android SDK allows you to define interactions that you can activate on the map to enable gestures and click events. The following interactions are supported –

Zoom Controls

The map supports the familiar two-finger pinch and zoom to change zoom level as well as double tap to zoom in.
You can disable zoom gestures by calling mMapView.setMultiTouchControls(false). This is independent of calling mMapView.setZoomLevel(int) to zoom in or out.

mMapView.setMapListener(new MapListener() {
    @Override
    public boolean onScroll(ScrollEvent event) {
                return false;
    }   @Override
public boolean onZoom(ZoomEvent event) {  
//this method captures the zoom event by the user.
return false;
} });

Current Location

Get the current user location using the GpsLocationProvider class.

UserLocationOverlay mLocationOverlay;
this.mLocationOverlay = new UserLocationOverlay(new GpsLocationProvider(getActivity()), mMapView);
mLocationOverlay.setCurrentLocationResId(R.drawable.ic_launcher);
mLocationOverlay.enableMyLocation();
mMapView.getOverlays().add(this.mLocationOverlay);
mMapView.invalidate();

Scroll Events

The map can be panned by simply dragging it around with a finger.

mMapView.setMapListener(new MapListener() {
    @Override
    public boolean onScroll(ScrollEvent event) {
//this method captures the on scroll event. 
         return false;
    }     @Override
public boolean onZoom(ZoomEvent event) {  
//this method captures the zoom event 
return false;
} });

Map Events

The SDK allows you to listen to certain events on the map. For example-

Zoom and Scroll Events

mMapView.setMapListener(new MapListener() {
    @Override
    public boolean onScroll(ScrollEvent event) {
                return false;
    }

    @Override
    public boolean onZoom(ZoomEvent event) {  
//this method captures the zoom event by the user.
        return false;
    }
});

Map Click/Long Press

If you want to respond to a user tapping on a point on the map, you can use a MapEventsOverlay which you need to add on the map as an Overlay –

MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(getActivity(), new MapEventsReceiver(){
  @Override
  public boolean singleTapConfirmedHelper(GeoPoint p) {
      return true;
  }
  @Override
  public boolean longPressHelper(GeoPoint p) {
      return true;
  }
});
mMapView.getOverlays().add(mapEventsOverlay);
mMapView.invalidate();

Map Overlays

The code samples that are part of the SDK detail out the usage of all the following features. It.s recommended that you browse the samples before integrating the SDK with your project. Feel free to reuse the code in the samples for your application.

Markers

Add a Marker

Add markers to the map by following these steps –

import com.mmi.layers.Marker;
Marker marker= new Marker(mMapView);
marker.setPosition(geoPoint);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
mMapView.getOverlays().add(marker);
mMapView.invalidate();

Remove a Marker

marker.remove(mMapView);

Customize a Marker

BasicInfoWindow infoWindow = new BasicInfoWindow(R.layout.tooltip, mMapView);
//infowindow gets displayed when you click on the marker.
infoWindow.setTipColor(getResources().getColor(R.color.base_color));
Marker marker = new Marker(mMapView);
marker.setTitle("Title(if any)");
marker.setDescription("Description(if any)");
marker.setSubDescription("Sub-Description(if any)");

Change default marker icon

marker.setIcon(R.drawable.yourIcon);

Marker Opacity

marker.setAlpha(float);

Info Windows

Add an info window that opens after a marker tap with the following lines of code –

BasicInfoWindow infoWindow = new BasicInfoWindow(R.layout.tooltip, mMapView); 
infoWindow.setTipColor(getResources().getColor(R.color.base_color)); 
Marker marker = new Marker(mMapView); 
marker.setTitle(title); 
marker.setDescription(description); 
marker.setSubDescription(subdescription); 
marker.setPosition(geoPoint); 
marker.setInfoWindow(infoWindow); 
mMapView.getOverlays().add(marker);
mMapView.invalidate();

Tooltips

You can customize the default tooltip by editing the tooltip.xml file in the layout folder of demo app or by copying the code snippet below. Do not change the ID values.

tooltip.xml

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
    android:orientation="vertical">

   <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:background="@color/base_color"
       android:orientation="vertical"
       android:padding="5dp">

       <TextView
           android:id="@+id/tooltip_title"
           android:layout_width="wrap_content"
           android:layout_height="0dp"
           android:layout_gravity="left"
           android:layout_weight="1"
           android:maxEms="17"
           android:textColor="@android:color/white"
           android:textSize="18sp" />

       <TextView
           android:id="@+id/tooltip_description"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:maxEms="17"
           android:textColor="@android:color/white"
           android:textSize="14sp"
           android:visibility="gone" />

       <TextView
           android:id="@+id/tooltip_sub_description"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:maxEms="17"
           android:textColor="@android:color/white"
           android:textSize="12sp"
      />

   </LinearLayout>

   <com.mmi.view.TipView
       android:id="@+id/tip_view"
       android:layout_width="fill_parent"
       android:layout_height="10dp" />
       </LinearLayout>

Marker Clustering

Add a cluster of markers that automatically expands and collapses using the following code –

MarkerClusterer markerClusterer = new MarkerClusterer(getActivity()); 
markerClusterer.setColor(getResources().getColor(R.color.green_color)); 
markerClusterer.mAnchorV = Marker.ANCHOR_CENTER; 
markerClusterer.mTextAnchorV = Marker.ANCHOR_CENTER; 
markerClusterer.setTextSize(12); 
ArrayList<GeoPoint> points = new ArrayList<>(); 
for (MarkerModel markerModel : markerModels) {//for MarkerModel please refer demo application 
  Marker marker = new Marker(mMapView); 
  marker.setTitle(markerModel.getTitle()); 
  marker.setDescription(markerModel.getDescription()); 
  marker.setIcon(getResources().getDrawable(R.drawable.marker_selected)); 
  marker.setPosition(markerModel.getGeoPoint()); 
 
 marker.setInfoWindow(null);// in case you dont want anything to get displayed when marker tapped 
  marker.setRelatedObject(markerModel); 
  markerClusterer.add(marker); 
  points.add(markerModel.getGeoPoint()); 
} 
mMapView.setBounds(points); 
mMapView.getOverlays().add(markerClusterer);
mMapView.invalidate();

Polylines

Add a Polyline

You can draw polylines to represent routes and other contiguous straight lines on the map

ArrayList geoPoints = new ArrayList<>();
PathOverlay pathOverlay = new PathOverlay(getActivity()); 
pathOverlay.setColor(getResources().getColor(R.color.base_color)); 
pathOverlay.setWidth(10); 
pathOverlay.setPoints(geoPoints); 
mMapView.getOverlays().add(pathOverlay);
mMapView.invalidate();

Remove a Polyline

mMapView.getOverlays().remove(pathOverlay);

Customize a Polyline

pathOverlay.setDescription("hi polyline");
pathOverlay.setTitle("set_title");
pathOverlay.setSubDescription("set_subDescription");
pathOverlay.setInfoWindow(yourInfoWindow);
pathOverlay.setImageUrl("Urlstring");

Polygons

Add a Polygon

Polygon polygon = new Polygon(getActivity());
polygon.setPoints(geoPoints);
polygon.setFillColor(Color.BLUE);
mMapView.getOverlays().add(polygon);
mMapView.invalidate();

Search

External libraries

Accessing the search functions in MapmyIndia Map SDK requires Google's GSON library. You must include it as a dependency.

Proguard

Using proguard? You must include following lines in proguard configuration file if you are using search functions in SDK.

-keepattributes Signature
-keepattributes *Annotation*
-keepattributes EnclosingMethod
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keep class com.mmi.apis.distance.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.apis.place.geocoder.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.apis.place.reversegeocode.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.apis.place.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.apis.routing.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.apis.place.autosuggest.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.apis.place.details.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.apis.place.nearby.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.services.account.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.services.api.** {
    <fields>;
    <methods>;
}
-keep class com.mmi.services.utils.** {
    <fields>;
    <methods>;
}

The following search services are available as part of the SDK bundled by default –

Geocoding

You can read more on MapmyIndia.s Geocoding API here. To geocode an address, create an instance of GeocodeManager class and call the getPlace method –

new MapmyIndiaGeocoding.Builder()
.setAddress("Delhi") 
.build()
.enqueueCall(new Callback<PlaceResponse>() {
@Override 
public void onResponse(Call<PlaceResponse> call, Response<PlaceResponse> response) { 
 //handle response 
 }
@Override 
public void onFailure(Call<PlaceResponse> call, Throwable t) {
t.printStackTrace();
	}
});

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 –

new MapmyIndiaReverseGeoCode.Builder()
.setLocation(28,77) 
.build(
.enqueueCall(new Callback() {
@Override 
public void onResponse(Call<PlaceResponse> call, 
Response<PlaceResponse> response) { 
//handle response 
}
@Override
public void onFailure(Call<PlaceResponse> call, Throwable t)  
} 
t.printStackTrace(); 
   }
});

.Auto Suggest

To find nearby places to a point, create an instance of NearbyManager class and call the getNearbyPlaces method with your search criteria

new MapmyIndiaAutosuggest.Builder<>() 
.setBridge(false) 
.setLocation(28,77)
.setQuery("mmi000") 
.build() 
.enqueueCall(new Callback<AutoSuggestAtlasResponse>() {  
@Override 
public void onResponse(Call<AutoSuggestAtlasResponse> call, Response<AutoSuggestAtlasResponse> response) { 
//handle response 
}
@Override
 public void onFailure(Call<AutoSuggestAtlasResponse> call, Throwable t) { 
  t.printStackTrace();  
   }
});

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.

new MapmyIndiaDirectionsLegacy.Builder() 
.setOrigin(Position.fromCoordinates(77,28)) 
.setDestination(Position.fromCoordinates(77.23,28.1231)) 
.build() 
.enqueueCall(new Callback(){ 
@Override 
public void onResponse(Call<LegacyRouteResponse> call,  Response<LegacyRouteResponse> response)  { 
//handle response 
}
@Override
 public void onFailure(Call<LegacyRouteResponse> call, Throwable t) {  
  t.printStackTrace();  
   }
});

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

Get driving time and distance between a center point and up to 10 destination points using MapmyIndia Maps Distance API.

ArrayList coordinates=new ArrayList<>(); 
coordinates.add(Point.fromLngLat(77.25,28.9231)); 
new MapmyIndiaDistanceLegacy.Builder() 
.setCenter(Point.fromLngLat(77.23,28.1231)) 
.setCoordinates(coordinates) 
.build() 
.enqueueCall(new Callback<LegacyDistanceResponse>() {  
@Override  
public void onResponse(Call call, Response response) { 
 //handle response 
  }
@Override 
public void onFailure(Call call, Throwable t) { 
t.printStackTrace(); 
   }
});

DistanceManager class provides three methods-

To set type of route

public void setRouteType(RouteType routeType)
//Possible input
RouteType.QUICKEST (default)
RouteType.SHORTEST

If user wants to avoid toll, ferries etc.

public void setAvoid(Avoid avoid
//Possible input
Avoid.TOLL_ROADS (default) 
Avoid.FERRIES
Avoid.UNPAVED_ROADS 
Avoid.HIGHWAYS

Select Vehicle type for travel -

public void setVehicleType(VehicleType vehicleType)
//Possible input
VehicleType.PASSENGER
VehicleType.TAXI

Nearby Places.

To find nearby places to a point, create an instance of NearbyManager class and call the getNearbyPlaces method with your search criteria

new MapmyIndiaNearby.Builder()
.setItemCount(10)
.setKeyword("Parking")
.setLocation(28,77)
.setExplain(false)
.setUsername("test")
.build() 
.enqueueCall(new Callback<NearbyAtlasResponse>() { 
@Override
  public void onResponse(Call<NearbyAtlasResponse> call, Response<NearbyAtlasResponse> response) { 
//handle response 
} 
@Override 
public void onFailure(Call<NearbyAtlasResponse> call, Throwable t) { 
t.printStackTrace();   
   }
});

eLoc / Place Details

To get suggestion on a given string, create an instance of AutoSuggestManager class and call the getSuggestions method with your search string

new MapmyIndiaELoc.Builder() 
 .setELoc("mmi000")
 .build() 
.enqueueCall(new Callback() {
@Override 
  public void onResponse(Call<PlaceResponse> call, Response response) { 
//handle response 
}
@Override
public void onFailure(Call<PlaceResponse> call, Throwable t)  
{ 
t.printStackTrace(); 
   }
});

Telematics

Live Location

This API returns accurate live location and related data of vehicles, assets & people with help of connected devices/sensors/mobiles to provide location awareness to users of your app. The API provides real-time visibility of your tracked objects, giving not just location information, but multiple additional fields which add value to your application. The API is capable of being used for multiple use cases: be it for transport - logistics or for personnel information services for all kinds of web or mobile development platforms.

Trips & Drive

This API is used to request the trip details of a vehicle in an account on our telematics platform. A vehicle can be a device/sensor connected to our telematics platform directly or via a third party data aggregator who utilises our telematics platform for tracking services. A trip or a drive is a list of reported geo-positions of any object (such as vehicles, assets or people) according to pre-defined conditions.

Geofence

The geofence and route APIs allow you to manage virtual geographical areas or geofences for your account on MapmyIndia's telematics platform. Geographic areas are defined as geometries in the form of geographic polygons, circles, or points that are relevant for any connected device/sensor: The presence or absence (entry or exit) of a vehicle to such geographic areas needs to be monitored and/or events generated on the basis of such transitions. The events might be alarms or reports of vehicles entering or exiting such geofences. These Geofence APIs allow you to create/edit/assign/delink/update geofences.

Historical Location

This API is used to get the historical location information as well as related additional information for a vehicle. This API can be used thus to create customized reports for users of your apps for different use cases, e.g.: plot the vehicle's past movements on map or get a historical graph of change in a vehicle's altitude.