Google Maps API-如何在不捕捉到位置的情况下移动地图?

时间:2018-10-05 14:30:39

标签: android google-maps maps

我开始自学将Android Studio用作学校项目,并希望在此应用中使用Google Maps API。

我有一张地图,上面有我的位置,但是每次移动相机时,它都会立即将相机重新定位到我的位置。

我当前的代码是这样:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    BitmapDrawable bitmapDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.my_marker_icon);
    Bitmap b = bitmapDrawable.getBitmap();
    Bitmap smallMarker = Bitmap.createScaledBitmap(b, 40, 40, false);
    mo = new MarkerOptions().position(new LatLng(0, 0)).title("My Current Location").icon(BitmapDescriptorFactory.fromBitmap(smallMarker));
    if (Build.VERSION.SDK_INT >= 23 && !isPermissionGranted()) {
        requestPermissions(PERMISSIONS, PERMISSION_ALL);
    } else requestLocation();
    if (!isLocationEnabled())
        showAlert(1);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    marker = mMap.addMarker(mo);
}

@Override
public void onLocationChanged(Location location) {
    LatLng myCoordinates = new LatLng(location.getLatitude(), location.getLongitude());
    marker.setPosition(myCoordinates);
    CameraUpdate center = CameraUpdateFactory.newLatLng(myCoordinates);
    CameraUpdate zoom = CameraUpdateFactory.zoomTo(15.0f);
    mMap.moveCamera(center);
    mMap.animateCamera(zoom);

}

0 个答案:

没有答案