android - 避免地图自动缩小android
问题描述
我在安卓中使用地图。这是我的 OnLocationChanged 方法,我的应用程序工作正常,但我正在缩放我的地图,它会在几秒钟后自动缩小……我在我的方法中使用上面的 MoveCamera。我在 Android Studio 中使用 MapsActivity 默认值。
public void onLocationChanged(Location location) {
mCurrentLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
//Toast.makeText(context, "Location Not Found.", Toast.LENGTH_SHORT).show();
}
//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 = mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12));
}
解决方案
您的地图不会自动缩小。它缩小了,因为您为它编写了代码
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12));
这在每次 onLocationChanged 和缩放时都有效。如果您想将相机移动到新位置但不想缩放,您可以尝试 CameraUpdateFactory 的 newLatLngBounds 功能
推荐阅读
- php - 如何使用 Apache 在 AWS EC2 实例上运行 PHP Ratchet WebSocket 应用程序
- arrays - 具有不同大小的二维数组分配问题 VHDL
- ios - 在苹果登录中使用客户端 ID 和密码的位置
- pyinstaller - 带有 pyinstaller 的脚本从 resource_filename 返回 TypeError 预期 str
- wordpress - 在 Wordpress 中创建自定义按钮的最佳实践
- c# - Azure Functions 调试计时器和 Http 触发器
- django - Django 测试与 1 个 DB 并行
- android - 如何从媒体商店 api 获取 mp3 格式的音频文件?
- sql - 在 SQL 外部表中需要一些时间来选择并将数据插入临时表
- vmware - 如何在 Centos7 中将 VMware VCenter 从 5.5 升级到 6.5(6.0)