我正在开发一个 Android 应用程序,它可以跟踪从当前位置到特定目的地的路径。它运作良好。但有一种异常(exception)情况。
当用户点击目的地标记时,需要将 map 移动到另一个具有缩放功能的位置。但只能缩放而不移动到第二个位置。
这是我与之相关的代码段。如果可以,请帮我解决这个问题。提前致谢。
double Kumana1_Latitude = 6.573022;
double Kumana1_Longitude = 81.666875;
double Kumana2_Latitude = 6.649353;
double Kumana2_Longitude = 81.770114;
final LatLng Kumana = new LatLng(Kumana1_Latitude, Kumana1_Longitude);
final LatLng Kumana2 = new LatLng(Kumana2_Latitude,Kumana2_Longitude);
Marker Kumana_marker = mGoogleMap.addMarker(new MarkerOptions()
.title("Kumana National Park")
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
.position(Kumana));
Kumana_marker.showInfoWindow();
mGoogleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker m) {
//here it get Zoomed, but does not move to the new location
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Kumana2, 13));
m.remove();
Toast.makeText(getApplicationContext(),
"Tap on the Kumana National Park entreance", Toast.LENGTH_LONG)
.show();
});
}
最佳答案
将标记放入 onLocationChanged()
并绘制标记。首先删除标记,然后添加具有新位置的新标记。
所有这些代码都必须在 onLocationChanged()
下
先检查
(if marker == null){
//plot marker
}
else{
//remove first marker..
//add new marker
}
关于android - Google map 不会移动到新的 LatLng 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25562147/