Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌地图不会移动到新位置_Android_Google Maps Markers_Google Maps Android Api 2 - Fatal编程技术网

Android 谷歌地图不会移动到新位置

Android 谷歌地图不会移动到新位置,android,google-maps-markers,google-maps-android-api-2,Android,Google Maps Markers,Google Maps Android Api 2,我正在开发一个Android应用程序,它可以追踪从当前位置到特定目的地的路径。它工作得很好。但有一个例外情况 当用户单击目标标记时,需要使用“缩放”将地图移动到另一个位置。但只进行缩放而不移动到第二个位置 这是我与之相关的代码段。如果你能帮我做这个。提前谢谢 double Kumana1_Latitude = 6.573022; double Kumana1_Longitude = 81.666875; double Kumana2_Latitude = 6.649353; double Ku

我正在开发一个Android应用程序,它可以追踪从当前位置到特定目的地的路径。它工作得很好。但有一个例外情况

当用户单击目标标记时,需要使用“缩放”将地图移动到另一个位置。但只进行缩放而不移动到第二个位置

这是我与之相关的代码段。如果你能帮我做这个。提前谢谢

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();
    });

            }    

尝试在重写的函数中调用
super.onMarkerClick(m)

将标记放入
onLocationChanged()
并绘制标记。首先移除标记,然后添加具有新位置的新标记

所有这些代码必须位于
onLocationChanged()下
先检查

(if marker == null){
//plot marker
}
else{
//remove first marker..
//add new marker
}

您是否尝试过使用
animateCamera