Nearby Search Widget
Introduction
The Mappls Nearby Widget makes it easy to integrate the functionality to search nearby POIs for selected categories in your Android application. The Nearby Search widget provided as a means to enable radially search for Nearby Places on Mappls Maps.
The widget offers the following basic functionalities:
Ability to search for nearby places directly with Mappls Maps visual interface.
A single method to initiate nearby search across all categories of places available on Mappls.
Ability to get information from Mappls Nearby Search widget through a callback.
This can be done by following simple steps.
Dependencies
- Add below dependency in your app-level build.gradle
implementation 'com.mappls.sdk:nearby-ui:1.0.0'
Step 2 :- Adding Credentials
Add your API keys to the SDK (in your application's onCreate() or before using map)
Java
MapplsAccountManager.getInstance().setRestAPIKey(getRestAPIKey());
MapplsAccountManager.getInstance().setMapSDKKey(getMapSDKKey());
MapplsAccountManager.getInstance().setAtlasClientId(getAtlasClientId());
MapplsAccountManager.getInstance().setAtlasClientSecret(getAtlasClientSecret());
Mappls.getInstance(applicationContext);
Kotlin
MapplsAccountManager.getInstance().restAPIKey = getRestAPIKey()
MapplsAccountManager.getInstance().mapSDKKey = getMapSDKKey()
MapplsAccountManager.getInstance().atlasClientId = getAtlasClientId()
MapplsAccountManager.getInstance().atlasClientSecret = getAtlasClientSecret()
Mappls.getInstance(applicationContext)
Step 3 :- Launching Nearby Widget
There are two ways to implement Nearby Search
widget:
- Using
MapplsNearbyFragment
- Using
MapplsNearbyActivity
MapplsNearbyFragment
Add MapplsNearbyFragment in your activity:
java
MapplsNearbyFragment nearbyFragment = MapplsNearbyFragment.newInstance();
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, nearbyFragment, MapplsNearbyFragment.class.getSimpleName())
.commit();
Kotlin
val nearbyFragment: MapplsNearbyFragment= MapplsNearbyFragment.newInstance()
supportFragmentManager.beginTransaction().add(R.id.fragment_container, nearbyFragment, MapplsNearbyFragment::class.java.simpleName)
.commit()
To get the selected nearby place use IMapplsNearbyCallback interface:
Java
nearbyFragment.setMapplsNearbyCallback(new IMapplsNearbyCallback() {
@Override
public void getNearbyCallback(NearbyAtlasResult nearbyAtlasResult) {
// Select place
}
});
Kotlin
nearbyFragment.setMapplsNearbyCallback(object : IMapplsNearbyCallback {
override fun getNearbyCallback(nearbyCallback: NearbyAtlasResult) {
//Select place
}
})
MapplsNearbyActivity
Add MapplsNearbyActivity in your activity:
java
Intent intent = new MapplsNearbyWidget.IntentBuilder().build(this);
startActivityForResult(intent, 101);
Kotlin
val intent = MapplsNearbyWidget.IntentBuilder().build(this)
startActivityForResult(intent, 101)
To get the selected POI:
java
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101 && resultCode == RESULT_OK) {
NearbyAtlasResult result = MapplsNearbyWidget.getNearbyResponse(data);
} }
Kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == 101 && resultCode == Activity.RESULT_OK) {
val place: NearbyAtlasResult? = MapplsNearbyWidget.getNearbyResponse(data!!)
} }