Find nearest POIs

Find nearest POIs using Woosmap API

  1. Use Search API to find the Nearest POIs
  2. Use a Distance provider to retrieve distance and duration value

Use Search API to find the Nearest POIs

You need a Private API key to request the Woosmap Search API.

To obtain on demand the closest POI from a location, you must instantiate the class PositionsManager call the method searchAPI and get the result on the callback SearchAPIReadyCallback or get the POI in the database inside the SDK.

In your activity, set keys and set a listener to monitor result of the SearchAPI request :

java
        @Override
protected void onCreate(Bundle savedInstanceState) {
    // Set Keys
    WoosmapSettings.privateKeyWoosmapAPI = woosmapPrivateKey;
    
    // Set the Search API listener 
    this.woosmap.setSearchAPIReadyListener(new WoosSearchAPIReadyListener());
}

    

To send request to the Search API, you can perform on demand requests to the Search API by using the following method:

java
        PositionsManager mPositionsManager = new PositionsManager(getContext(), WoosmapDb.getInstance(getContext()));

mPositionsManager.searchAPI(latitude, longitude, locationId);

    

Woosmap Search API Ready Listener

Create a listener connected to the interface Woosmap.SearchAPIReadyListener and set a callback to retrieve POI data.

java
        public class WoosSearchAPIReadyListener implements Woosmap.SearchAPIReadyListener {
    public void SearchAPIReadyCallback(POI poi) {
        // result of Search API request
    }
}

    

Retrieve POI data

All result of request SearchAPI are strored in the SDK database, you can retrieve data from the SDK database like this :

java
        POI[] poiList = WoosmapDb.getInstance(getApplicationContext()).getPOIsDAO().getAllPOIs();

    

Important : all interaction with the database must be launch in a asynchronous task.

Request Parameters

Set parameter to narrow your results or filters it with the query parameter. More details in the Woosmap Search API documentation:

java
        WoosmapSettings.searchAPIParameters.put("radius","5000");
WoosmapSettings.searchAPIParameters.put("query","type:\"click&collect\"");

    

Use a Distance provider to retrieve distance and duration value

As for the Search API, request to the Distance provider can be done on demand.

In your activity, instantiate Woosmap, define a Distance provider, set keys, specifies the mode of transport to use when calculating distance and set a listener to monitor result of the Distance request:

java
        @Override
protected void onCreate(Bundle savedInstanceState) {
    // Set Keys
    WoosmapSettings.privateKeyWoosmapAPI = woosmapPrivateKey;
    
    // Set the Distance API listener 
    this.woosmap.setDistanceReadyListener(new WoosDistanceReadyListener());
    
    // [...]
}

    

Distance Delegate

Create a listener connected to the interface Woosmap.DistanceReadyListener and set a callback to retrieve distance and duration values.

java
        public class WoosDistanceReadyListener implements Woosmap.DistanceReadyListener {
    public void DistanceReadyCallback(Distance[] distances) {
        // result of Distance request
    }
}

    

Send request to retrieve distance and duration data

As for the Search API, if you need to trigger distance requests (to calculate distance and duration) by your own, you can perform on demand requests to the Distance provider. Parameters are optional, if not defined, tracking profile values are used as default value.

java
        PositionsManager mPositionsManager = new PositionsManager(getContext(), WoosmapDb.getInstance(getContext()));

// set latitude and longitude of the origin
Double latOrigin = currentPosition.getLatitude();
Double lngOrigin = currentPosition.getLongitude();

// set the latitude and longitude of destinations,
List<Pair<Double, Double>> listDestinationPoint = new ArrayList<>();
listDestinationPoint.add(new Pair(place.getLatitude(), place.getLongitude()));

Map<String, String> param = new HashMap<String, String>();

// [OPTIONAL] change the travel mode ("walking", "cycling" or "driving")
param.put( "distanceMode","walking" );

// [OPTIONAL] change the distance units ("imperial" or "metric")
param.put( "distanceUnits","imperial" );

// [OPTIONAL] change the language for textual result (example: "en", "fr")
param.put( "distanceLanguage","en" );

// Enable/Disable traffic data
Boolean distanceWithTraffic = true;

mPositionsManager.calculateDistance(latOrigin, lngOrigin, listDestinationPoint, param, place.getLocationId(), distanceWithTraffic);

    
Was this article helpful?
Have more questions? Submit a request