Skip to main content

Nearby Search

Introduction

A simple plugin / widget to search for nearby places powered by the best online maps from Mappls. The Nearby Search plugin for Mappls Web Map JS library is provided as a means to enable radially searching for Nearby Places on Mappls Maps.

The plugin can be used in combination with our Interactive Map JS library but it also possesses the adaptability to be used as an independent plugin within any web app implementation. Thus it enables developers to include Mappls web JS in their own customized solutions easily.

The SDK offers the following basic functionalities:

  1. Ability to search for nearby places directly with or without Mappls Maps visual interface.
  2. A Mappls.nearby() method to initiate nearby search across all categories of places available on Mappls.
  3. Ability to get information from Mappls Place Search plugin through a callback
  4. Include the Nearby Search Plugin with or without an interactive Map component.

Sample Implementation

Visit the samples for assistance to create a sample implementation with your own keys.

For detailed understanding of the plugin, Let’s get started!

Plugin's Configurations

Adding the Nearby Search plugin in the script

<script src="https://apis.mappls.com/advancedmaps/api/{token-OR-JWT-key}/map_sdk_plugins?v=3.0&libraries=nearby"></script>

Initializing the Nearby Search plugin

Method

mappls.nearby()

/*Nearby plugin initialization*/
var options = {
divId: 'nearby_search',
map: map,
keywords: 'atm',
refLocation: [28.632735, 77.219696],
fitbounds: true,
geolocation: true,
click_callback: function(d) {
alert(d);
}
}

mappls.nearby(options, callback);

Mandatory Parameters

  1. keywords: The string or JSON object which will be passed as input query to the search engine. Examples
    • As a string: keywords:"atm". This parameter supports input in Hindi Language keywords:"चाय". To get the feature contact apisupport@mapmyindia.com.
    • As a JSON object: keywords:{'FINATM':'ATMS','FODCOF':'Restaurants'}. This parameter supports input in Hindi Language keywords:{'एचडीएफसी ':'एटीएम'}. To get the feature contact apisupport@mapmyindia.com. This mechanism is used to display a selection of POI categories on a UI. If keywords parameter is used, then refLocation input also becomes mandatory.
  2. callback: (method): results will be returned in this method if specified.

OR

  1. hyperLink: This is the URL received from Mappls Place Search plugin for bridged Nearby Search. i.e. A Nearby Search trigerred directly from the Place Search Plugin.

Optional Parameters

  1. refLocation: location coordinates which will be used as centroid of the radial search reference.
    e.g. refLocation:[28.61, 77.23] OR refLocation:[28.61, 77.23]
  2. map: A map object from our Maps SDK. Markers can also be passed here that will be displayed on map. Custom icons also can be passed here.
  3. divId: The HTML where developer wishes results to be displayed. Example: divId:document.getElementbyId('Nrdiv');
  4. divHeight: (in pixels) for customizing or improving results display UI.
  5. icon: (object) To set the icons of the resulting categories of results.
    • Single Category: Example:
      icon: {
      url: '2.png'
      }
      OR
      icon: {
      html: " < div > < img src = 'pin.png' > < /div>",
      width: 30,
      height: 40
      }
    • Multiple Category: Example:
      icon: {
      'FINATM': {
      url: 'atm.png',
      height: 40,
      width: 30
      },
      'FODCOF': {
      url: 'food.png',
      height: 40,
      width: 32
      }
      }
      Optional parameters for icon configuration are as follows:
      • offset: Example: offset:[20,40]
      • popupAnchor: Example: popupAnchor:[-10,20]
  6. popup: (boolean) Default is true if map is used. Used to bind popup to markers.
  7. popupOptions: (object) Used to define pop up optional configuration.
    Example: popupOptions: {maxWidth:250}
  8. fitbounds: (boolean) Default is true. Used to fit all markers to in map view bound.
  9. geolocation: boolean value used to enable or disable current location selection . Default is true.
  10. radius: (number): Defines the radius of nearby search.
  11. bounds: (geographic bounds): Used to define the rectangular bounds within which nearby search will work.
  12. sortBy: (string)Used to sort the nearby search results.
  13. page: (number): to request another page of results if available.
  14. pod: (string): to filter to a certain type of results.
  15. callback_click: (method): a method that will be called when user clicks on any listing. The action returns the eLoc of the selected place.

Types of Nearby Search Implementations

1. Get data from category & coordinates

Following is an example of calling mappls.nearby() method to get data from category and coordinates:

var res=mappls.nearby({keywords:"atm",refLocation:"123ZRR"});

2. Get data from Mappls Search category url

var res=mappls.nearby({hyperLink:'https://atlas.mapmyindia.com/api/places/nearby/json?explain&richData&&refLocation=28.61,77.23&keywords=FINATM'});

3. Get data from category & location selection UI

var res=mappls.nearby({divId:'nearby_divId',keywords:{'FINATM':'ATMs', 'FODCOF':'Restaurants'}});

This will place a selection of keywords and a location selection UI inside divId.

Remove Nearby Markers within callback from Map

Use remove() method to remove markers from map.

var markers=res.markers();
markers.remove();

Add Event to Markers

Use addListener() method to associate events to markers.

markers.addListener('click',function(data){ console.log(data);});