背景:我正在开发一个应用程序,该应用程序允许用户在 20 英里半径范围内看到其他用户。当他们登录时,他们会被发送到 MapsActivity,该活动会缩放到他们当前的位置,并显示 20 英里内的任何其他在线用户。
问题:每次我在地图上滚动时,我都会回到我当前的位置,如果我缩小或缩小,它会重新放大到我设置的相同缩放。我什至试过这条线,但它没有用:
eaterGoogleMap.getUiSettings().setAllGesturesEnabled(true);
我需要做的事情:当他们第一次在我的应用程序中打开 MapsActivity 时缩放到他们的位置。允许用户像在 Google Maps App 中一样滚动地图,并在移动时更新他们的位置,就像在 Google Maps App 中一样。
我做了什么:
@Override
public void onConnected(Bundle bundle) {
// Constantly Update User location every 1.1 seconds!
locationRequest = new LocationRequest();
locationRequest.setInterval(1100);
locationRequest.setFastestInterval(1100);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
return;
}
Log.d("reque", "check here");
}
@Override
public void onLocationChanged(Location location) {
lastLocation = location;
if (currentUserLocationMarker != null) {
currentUserLocationMarker.remove();
}
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(getString(R.string.user_current_location_marker_title));
markerOptions.visible(false);
currentUserLocationMarker = eaterGoogleMap.addMarker(markerOptions);
float zoom = 17.0f;
eaterGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
eaterGoogleMap.getUiSettings().setZoomControlsEnabled(true);
eaterGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));
eaterGoogleMap.getUiSettings().setRotateGesturesEnabled(false);
// Begin to locate all online Vendors to display on map
locateOnlineVendors();
}