Easy To Integrate Maps & Location APIs & SDKs For Web & Mobile Applications Powered with India’s most comprehensive and robust mapping functionalities. Now Available for Srilanka, Nepal, Bhutan and Bangladesh
-
You can get your api key to be used in this document here: https://www.mapmyindia.com/api/signup
-
The sample code is provided to help you understand the basic functionality of MapmyIndia maps & REST APIs working on Android native development platform.
3.Explore through 200+ countries & territories with Global Search, Routing and Mapping APIs & SDKs by Mappls.
Mappls Maps SDK for Android lets you easily add Mappls Maps and web services to your own Android application. The SDK for Android supports API 21+. You can have a look at the map and features you will get in your own app by using the Mappls Maps SDK for Android.
Through customized 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. The SDK handles downloading of map tiles and their display along with a bunch of controls and native gestures.
Follow these steps to add the SDK to your project –
- Create a new project in Android Studio For older Build versions (i.e, Before gradle v7.0.0)
- Add Mappls repository in your project level
build.gradle
allprojects {
repositories {
maven {
url 'https://maven.mappls.com/repository/mappls/'
}
}
}
For Newer Build Versions (i.e, After gradle v7.0.0)
- Add MapmyIndia repository in your
settings.gradle
dependencyResolutionManagement {
// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url 'https://maven.mappls.com/repository/mappls/'
}
}
}
- Add below dependency in your app-level
build.gradle
implementation 'com.mappls.sdk:mappls-android-sdk:8.0.0'
implementation 'com.mappls.sdk:annotation-plugin:1.0.0'
- Add these permissions in your project
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
add following lines in your app module’s build.gradle
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
Add your API keys to the SDK (in your application’s onCreate() or before using map)
MapplsAccountManager.getInstance().restAPIKey = "SET_REST_API_KEY"
MapplsAccountManager.getInstance().mapSDKKey = "SET_MAP_KEY"
MapplsAccountManager.getInstance().atlasClientId = "SET_CLIENT_ID"
MapplsAccountManager.getInstance().atlasClientSecret = "SET_CLIENT_SECRET"
Mappls.getInstance(applicationContext)
You cannot use the Mappls Map Mobile SDK without these function calls. You will find your keys in your API Dashboard.
To make Jetpack compose Support
@Composable
fun MapplsMap(
modifier: Modifier = Modifier,
onSuccess: ((MapView, MapplsMap) -> Unit)? = null,
onError: ((Int, String?) -> Unit)? = null
) {
val mapView = MapView()
AndroidView(
factory = { mapView },
modifier = modifier
) {
it.getMapAsync(object : OnMapReadyCallback {
override fun onMapReady(p0: MapplsMap) {
onSuccess?.invoke(it, p0)
}
override fun onMapError(p0: Int, p1: String?) {
onError?.invoke(p0, p1)
}
})
}
}
@Composable
private fun MapView(): MapView {
val context = LocalContext.current
val mapView = remember {
MapView(context)
}
val lifecycle = LocalLifecycleOwner.current.lifecycle
DisposableEffect(lifecycle, mapView) {
// Make MapView follow the current lifecycle
val lifecycleObserver = getMapLifecycleObserver(mapView)
lifecycle.addObserver(lifecycleObserver)
onDispose {
mapView.onResume()
mapView.onStop()
mapView.onDestroy()
lifecycle.removeObserver(lifecycleObserver)
}
}
return mapView
}
/**
* Handles lifecycle of provided mapView
**/
private fun getMapLifecycleObserver(mapView: MapView): LifecycleEventObserver =
LifecycleEventObserver { _, event ->
when (event) {
Lifecycle.Event.ON_CREATE -> mapView.onCreate(Bundle())
Lifecycle.Event.ON_START -> mapView.onStart()
Lifecycle.Event.ON_RESUME -> mapView.onResume()
Lifecycle.Event.ON_PAUSE -> mapView.onPause()
Lifecycle.Event.ON_STOP -> mapView.onStop()
Lifecycle.Event.ON_DESTROY -> mapView.onDestroy()
else -> throw IllegalStateException()
}
}
To use Mappls Map
MapplsMap(onSuccess = { mapView, mapplsMap->
},
onError = { code, message ->
})
onSuccess callback provides MapView
and MapplsMap
which is used to perform different operations.
@Composable
fun AddMarkerScreen() {
Scaffold(topBar = {
TopAppBar(title = { Text(text = "Add Marker") })
}) {
Column {
MapplsMap(onSuccess={ mapView, mapplsMap ->
mapplsMap.getStyle {
val symbolManager = SymbolManager(mapView, mapplsMap, it)
symbolManager.create(SymbolOptions().position(LatLng(27.0, 77.0)))
}
mapplsMap.cameraPosition = CameraPosition.Builder()
.target(LatLng(27.0, 77.0))
.zoom(14.0)
.build()
},
onError = { _, _ ->
})
}
}}
For any queries and support, please contact:
Email us at apisupport@mappls.comSupport Need support? contact us!