[Mapbox-Android]如何显示用户位置附近的所有商店、医院?
[Mapbox-Android]How can I show all the shops,hospitals near users location?
有教程:https://docs.mapbox.com/help/tutorials/android-store-locator/
这显示了如何手动添加我们的商店,创建数据集并在我们的应用程序中显示。我想获取特定用户位置附近的所有医院、银行。我怎样才能做到这一点?请帮忙!
您需要使用 Mapbox Tilequery API 来查询 Mapbox Streets 的 building
层或查询您自己的具有 bank/hospital 数据的自定义样式。
https://docs.mapbox.com/android/java/overview/tilequery/
https://docs.mapbox.com/android/java/examples/tilequery/
使用 https://docs.mapbox.com/playground/tilequery/ to play with the Mapbox Tilequery API. For example, https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/-122.4052,37.7564.json?limit=19&radius=536&layers=building&dedupe=true&access_token=PASTE_YOUR_MAPBOX_TOKEN_HERE 可以得到 FeatureCollection
个 Feature
个对象。循环遍历每个Feature
,看是否是type
属性是hospital
、bank
等
关于将设备位置用于 Tilequery 请求:
设置 LocationComponent
如 https://docs.mapbox.com/android/maps/examples/show-a-users-location 所示。然后您可以执行以下操作来获取设备位置:
locationComponent.getLastKnownLocation().getLatitude();
locationComponent.getLastKnownLocation().getLongitude();
或者如果您需要跟踪设备位置:
https://docs.mapbox.com/help/tutorials/android-location-listening
https://docs.mapbox.com/android/maps/examples/location-change-listening
有教程:https://docs.mapbox.com/help/tutorials/android-store-locator/ 这显示了如何手动添加我们的商店,创建数据集并在我们的应用程序中显示。我想获取特定用户位置附近的所有医院、银行。我怎样才能做到这一点?请帮忙!
您需要使用 Mapbox Tilequery API 来查询 Mapbox Streets 的 building
层或查询您自己的具有 bank/hospital 数据的自定义样式。
https://docs.mapbox.com/android/java/overview/tilequery/
https://docs.mapbox.com/android/java/examples/tilequery/
使用 https://docs.mapbox.com/playground/tilequery/ to play with the Mapbox Tilequery API. For example, https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/-122.4052,37.7564.json?limit=19&radius=536&layers=building&dedupe=true&access_token=PASTE_YOUR_MAPBOX_TOKEN_HERE 可以得到 FeatureCollection
个 Feature
个对象。循环遍历每个Feature
,看是否是type
属性是hospital
、bank
等
关于将设备位置用于 Tilequery 请求:
设置 LocationComponent
如 https://docs.mapbox.com/android/maps/examples/show-a-users-location 所示。然后您可以执行以下操作来获取设备位置:
locationComponent.getLastKnownLocation().getLatitude();
locationComponent.getLastKnownLocation().getLongitude();
或者如果您需要跟踪设备位置:
https://docs.mapbox.com/help/tutorials/android-location-listening
https://docs.mapbox.com/android/maps/examples/location-change-listening