I'm developing an app and I'm trying to implement a means of listing stores close to the user's current location using the android mapbox SDK. Can anyone give a help how can I implement this?
-
1Kindly use Google search for such broad questions. Post problem/code specific questions here. – Abhimanyu May 14 '19 at 13:43
2 Answers
You could use the Mapbox Tilequery API to query Point
s in the building
layer of the Mapbox Streets style. Check the type
property for each Feature
that is in the API response's FeatureCollection
. Check that the type
is a store, rather than coffee shops, salons, etc. Use the LocationComponent
's getLastKnownLocation
as the query coordinate.
https://docs.mapbox.com/android/java/examples/tilequery
https://docs.mapbox.com/android/maps/examples/show-a-users-location
If you want to listen to device location changes: https://docs.mapbox.com/help/tutorials/android-location-listening/
Or you could query rendered Feature
s on a specific layer:
https://docs.mapbox.com/android/maps/overview/query/
https://github.com/mapbox/mapbox-android-demo/search?utf8=%E2%9C%93&q=queryRenderedFeatures&type=
https://docs.mapbox.com/android/maps/examples/count-features-in-a-selected-area/

- 2,529
- 1
- 11
- 13
you should calculate the distance between the user position and store position , you can do this using this method :
private static double distance(double lat1, double lon1, double lat2, double lon2, String unit) {
if ((lat1 == lat2) && (lon1 == lon2)) {
return 0;
}
else {
double theta = lon1 - lon2;
double dist = Math.sin(Math.toRadians(lat1)) * Math.sin(Math.toRadians(lat2)) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.cos(Math.toRadians(theta));
dist = Math.acos(dist);
dist = Math.toDegrees(dist);
dist = dist * 60 * 1.1515;
if (unit == "K") {
dist = dist * 1.609344;
} else if (unit == "N") {
dist = dist * 0.8684;
}
return (dist);
}
}

- 5,748
- 2
- 21
- 38