简体   繁体   English

缩放Google Maps Android Firebase

[英]Zoom Google Maps Android Firebase

I'm doing my car tracking application. 我正在做我的汽车追踪应用程序。 The problem is that when I zoomed in or out, the zoom restarts its position. 问题是当我放大或缩小时,变焦会重新开始其位置。 And when I look at another part of the map, it returns me to my location. 当我查看地图的另一部分时,它使我回到自己的位置。 How can I solve that? 我该如何解决?

public void onLocationChanged(Location location) {

   if(getApplicationContext()!=null){
        mLastLocation = location;

        LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());

        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
    }
}

@Override
public void onConnected(@Nullable Bundle bundle) {
    mLocationRequest = LocationRequest.create();
    mLocationRequest.setInterval(1000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(CustomerMapActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);
    }
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);

}

The issue is, with every new location update, your are moving and zooming the camera so you need remove 问题在于,每次进行新的位置更新时,您都在移动和缩放相机,因此需要移除

public void onLocationChanged(Location location) {

   if(getApplicationContext()!=null){
        mLastLocation = location;

        LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
        // remove to stop frequent camera movement
        //mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        //mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
    }
}

or alternatively, you can increase the location retrieval interval to give user some more time as 或者,您可以增加位置检索间隔,以便为用户提供更多时间,例如

mLocationRequest.setInterval(10000);
mLocationRequest.setFastestInterval(5000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM