【发布时间】:2023-04-07 20:19:01
【问题描述】:
我已成功从数据库中存储的一些数据中获取纬度和经度。但我无法更新地图上的标记位置。请有人帮助我提供代码或如何做到这一点。
【问题讨论】:
标签: android android-studio google-maps-markers android-maps-v2
我已成功从数据库中存储的一些数据中获取纬度和经度。但我无法更新地图上的标记位置。请有人帮助我提供代码或如何做到这一点。
【问题讨论】:
标签: android android-studio google-maps-markers android-maps-v2
使用CameraUpdate 试试这个,
LatLng coordinate = new LatLng(lat, lng); //Store these lat lng values somewhere. These should be constant.
CameraUpdate location = CameraUpdateFactory.newLatLngZoom(coordinate, 15);
mMap.animateCamera(location);
或者也可以用这个,
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(totalAddress); //Here Total Address is address which you want to show on marker
mMap.clear();
markerOptions.icon(
BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
markerOptions.getPosition();
mCurrLocationMarker = mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
【讨论】:
markerOptions.getPosition() 将返回我们使用markerOptions.position(latLng) 在它上面设置的那个。那不是设备的当前位置。