Skip to content

MapmyIndia Nearby Search Widget

Saksham66 edited this page Apr 23, 2021 · 4 revisions

MapmyIndia APIs

MapmyIndia Nearby Search Widget

The MapmyIndia 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 MapmyIndia Maps.

The widget offers the following basic functionalities:

  • Ability to search for nearby places directly with MapmyIndia Maps visual interface.

  • A single method to initiate nearby search across all categories of places available on MapmyIndia.

  • Ability to get information from MapmyIndia Nearby Search widget through a callback.

This can be done by following simple steps.

Follow these steps to add the widget to your project –

  • Create a new project in Android Studio
  • Add MapmyIndia repository in your project level build.gradle
 allprojects {  	
    repositories {  	
    	
        maven {  	
            url 'https://maven.mapmyindia.com/repository/mapmyindia/' 	
        }  	
    }  	
}	
  • Add below dependency in your app-level build.gradle
   implementation 'com.mapmyindia.sdk:nearby-ui:0.1.0'

Add your API keys to the SDK (in your application's onCreate() or before using map)

Java

MapmyIndiaAccountManager.getInstance().setRestAPIKey(getRestAPIKey());  	
MapmyIndiaAccountManager.getInstance().setMapSDKKey(getMapSDKKey());  		
MapmyIndiaAccountManager.getInstance().setAtlasClientId(getAtlasClientId());  	
MapmyIndiaAccountManager.getInstance().setAtlasClientSecret(getAtlasClientSecret());  	
MapmyIndia.getInstance(applicationContext);

Kotlin

MapmyIndiaAccountManager.getInstance().restAPIKey = getRestAPIKey()  	
MapmyIndiaAccountManager.getInstance().mapSDKKey = getMapSDKKey()  		
MapmyIndiaAccountManager.getInstance().atlasClientId = getAtlasClientId()  	
MapmyIndiaAccountManager.getInstance().atlasClientSecret = getAtlasClientSecret()	
MapmyIndia.getInstance(applicationContext)

There are two ways to implement Nearby Search widget:

  • Using MapmyIndiaNearbyFragment
  • Using MapmyIndiaNearbyActivity

MapmyIndiaNearbyFragment

Add MapmyIndiaNearbyFragment in your activity:

java

MapmyIndiaNearbyFragment nearbyFragment = MapmyIndiaNearbyFragment.newInstance();

getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, nearbyFragment, MapmyIndiaNearbyFragment.class.getSimpleName())  
        .commit();  

Kotlin

val nearbyFragment: MapmyIndiaNearbyFragment= MapmyIndiaNearbyFragment.newInstance()
supportFragmentManager.beginTransaction().add(R.id.fragment_container, nearbyFragment, MapmyIndiaNearbyFragment::class.java.simpleName)  
        .commit()

To get the selected nearby place use IMapmyIndiaNearbyCallback interface:

Java

nearbyFragment.setMapmyIndiaNearbyCallback(new IMapmyIndiaNearbyCallback() {  
    @Override  
    public void getNearbyCallback(NearbyAtlasResult nearbyAtlasResult) {  
       // Select place
    }    
});

Kotlin

nearbyFragment.setMapmyIndiaNearbyCallback(object : IMapmyIndiaNearbyCallback {  
    override fun getNearbyCallback(nearbyCallback: NearbyAtlasResult) {  
        //Select place  
    }  
})

MapmyIndiaNearbyActivity

Add MapmyIndiaNearbyActivity in your activity:

java

 Intent intent = new MapmyIndiaNearbyWidget.IntentBuilder().build(this);   
 startActivityForResult(intent, 101);  

Kotlin

val intent = MapmyIndiaNearbyWidget.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 = MapmyIndiaNearbyWidget.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? = MapmyIndiaNearbyWidget.getNearbyResponse(data!!)              
} }  

Email

Email us at apisupport@mapmyindia.com

Stack Overflow

Ask a question under the mapmyindia-api

Support

Need support? contact us!

Blog

Read about the latest updates & customer stories

© Copyright 2021. CE Info Systems Pvt. Ltd. All Rights Reserved. | Terms & Conditions.

Clone this wiki locally