android - 在mapbox中,当我点击android上的按钮时如何返回我的位置
问题描述
单击按钮时如何返回我的位置,就像谷歌地图一样。我想单击一个按钮并在 mapbox 中显示我的位置。我应该怎么办?
解决方案
您可以在LocationComponent
此处添加通过说明https://docs.mapbox.com/android/maps/overview/location-component/
LocationComponent
Mapbox Android 演示应用中还有一个基本示例: https ://github.com/mapbox/mapbox-android-demo/blob/master/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/location/ LocationComponentActivity.java
一切设置好后,您将把 Mapbox 地图相机移动到按钮 中的最后一个已知位置onClick()
。
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Location lastKnownLocation = mapboxMap.getLocationComponent().getLastKnownLocation();
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(
new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude())));
}
});
animateCamera()
是另一种选择,而不是moveCamera()
如果您愿意。
推荐阅读
- jquery - ajax请求后Bootstrap Toogle失败
- facebook - 如何使用 Zapier 向 Facebook Pixel 发送自定义事件
- java - 无法将“azure.servicebus.subscription-receive-mode”下的属性绑定到 com.microsoft.azure.servicebus.ReceiveMode:
- python - 将 numpy 数组写入文本文件的速度
- ambiguous - 调用 String.Split() 时发现不明确的匹配
- visual-studio - 为什么我不能选择目标框架 4.7.1 但可以选择 4.7.2?
- c# - Polly Bulkhead 策略本身是否会调用线程?
- c++ - 向作用域枚举添加按位运算和转换为布尔值 - 圣诞探索
- apache-kafka - 如何控制/暂停子源/流中的akka流流
- python - 在 Python 中使用 Pefile 查找可执行文件的 DLL 的绝对路径