我正在开发一个应用,并且正在尝试使用android mapbox SDK实现一种列出靠近用户当前位置的商店的方法。谁能帮我该怎么实现?
答案 0 :(得分:3)
您可以使用the Mapbox Tilequery API在Mapbox Streets样式的POI标签层中查询Point
。过滤商店而不是咖啡馆,沙龙等的结果。使用LocationComponent
的{{1}}作为查询坐标。
https://docs.mapbox.com/android/java/examples/tilequery
https://docs.mapbox.com/android/maps/examples/show-a-users-location
如果您想收听设备位置更改:https://docs.mapbox.com/help/tutorials/android-location-listening/
或者您可以在特定图层上查询渲染的getLastKnownLocation
:
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/
答案 1 :(得分:0)
您应该计算用户位置和商店位置之间的距离,可以使用以下方法进行操作:
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);
}
}