android - Google Maps API - 如何在不捕捉位置的情况下移动地图?
问题描述
作为一个学校项目,我开始自学使用 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);
}
解决方案
推荐阅读
- azure - 如何恢复到 Azure Function App 的经典身份验证
- ios - prefersLargeTitles 属性中文本的字体属性是什么?
- python - 调用 tf.data.Dataset.map 时未更新全局变量
- kubernetes - Kubernetes:“Liveness probe failed:rm: cannot remove '/tmp/healthy': No such file or directory”
- vue.js - Vue:使用复选框在结果数组之间切换
- c# - SendInfoTo(NetState, bool, bool)' 返回 void,return 关键字后面不能跟对象表达式
- python - Django:如何获得多个输入?
- python - 如何使用实际的 csv 文件而不是 stringIO 编写脚本
- phpstorm - Tailwind CSS 的 PhpStorm 自动完成功能不起作用
- java - 如果我将属性放在 maven pom.xml 的属性标签中会发生什么