通过拖动在相机中移动时,它总是每秒移动到当前位置

while moving in camera by dragging it always moves to current location every second

通过拖动移动到地图时它总是每秒移动回当前位置,我无法在地图中看到我所在位置附近的视图,如何阻止它每秒移动到当前位置?。我只想在单击我的位置按钮时移动到我的位置..所以有人可以帮助我吗?提前致谢。我的代码是

@Override
public void onLocationChanged(Location location)
{
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}

//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
/*MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
*/

CameraUpdate center=
CameraUpdateFactory.newLatLng(latLng);
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15.0f);

mGoogleMap.moveCamera(center);
mGoogleMap.animateCamera(zoom);
//move map camera
// mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,15.0f));

}

我已经实现了一个条件来实现你的目标。它会在第一次调用 onLocationChanged() 时将相机移动到当前位置。之后它会每秒捕获当前位置并将其存储到 mLastLocation = location; 但它不会移动相机。当用户按下按钮时,它将从 mLastLocation 获取 LatLong 并将相机移动到您想要的当前位置。

boolean isFirstTime = true;   

    @Override
public void onLocationChanged(Location location)
{
   mLastLocation = location;
   if (mCurrLocationMarker != null) {
     mCurrLocationMarker.remove();
   }

  if(isFirstTime){
    //Place current location marker
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    /*MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Current Position");
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
    */

    CameraUpdate center=
    CameraUpdateFactory.newLatLng(latLng);
    CameraUpdate zoom=CameraUpdateFactory.zoomTo(15.0f);

    mGoogleMap.moveCamera(center);
    mGoogleMap.animateCamera(zoom);
    //move map camera
   // mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,15.0f));
   isFirstTime = false;
  }

}

在按钮上单击:

btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 LatLng latLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
                 CameraUpdate center=
                 CameraUpdateFactory.newLatLng(latLng);
                 CameraUpdate zoom=CameraUpdateFactory.zoomTo(15.0f);    
                 mGoogleMap.moveCamera(center);
                 mGoogleMap.animateCamera(zoom);
            }
        });

非常简单。我总是在地图上标记新位置。

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == RESULT_OK) {

                Place place = PlacePicker.getPlace(this,data);

                CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(place.getLatLng())
                        .zoom(17).build();

                Marker marker = mMap.addMarker(new MarkerOptions().position(place.getLatLng()).title(place.getName().toString()));
                markers.add(marker);

                mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

            }
        }

我将相机移动到标记位置。让我知道它是否有效,我会帮助你:)