当我单击按钮时,如何返回我的位置,就像Google地图一样。 我想单击一个按钮,然后在mapbox中显示我的位置。 我该怎么办?
答案 0 :(得分:1)
您可以通过此处的https://docs.mapbox.com/android/maps/overview/location-component/
来添加LocationComponent
Mapbox Android演示应用程序中还有一个基本的LocationComponent
示例: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()
。