通过拖动 move 到 map 时,它总是每秒 move 回当前位置,我无法在 map 中看到我所在位置附近的 View ,如何阻止它每秒 move 到当前位置?。我只想在单击我的位置按钮时 move 到我的位置..所以有人可以帮助我吗?提前致谢。我的代码是
@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()
时,它会将相机 move 到当前位置。之后它会每秒捕获当前位置并将其存储到 mLastLocation = location;
但它不会 move 相机。当用户按下按钮时,它会从 mLastLocation
获取 LatLong
并将相机 move 到您想要的当前位置。
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);
}
});
关于android - 通过拖动在相机中 move 时,它总是每秒 move 到当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43230052/