我想以5秒的固定间隔更新googleMap中的标记位置。我从服务器获得不同的纬度和经度值,我需要使用标记在googleMap中显示。我尝试了以下内容,
void updateCabLocation(final LatLng location) {
if(myMarker == null) {
myMarker = mGoogleMap.addMarker(new MarkerOptions().position(location).
icon(BitmapDescriptorFactory.fromResource(R.drawable.myMarkerImage)));
}else {
myMarker.setPosition(location);
}
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(location, 15);
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(location));
mGoogleMap.animateCamera(cameraUpdate);
}
Runnable updateMarker = new Runnable() {
@Override
public void run() {
updateCabLocation(location); // location value changes each time. I have deleted that piece of code here.
handler.postDelayed(updateMarker, 5000);
}
};
我以5秒的固定间隔调用updateCabLocation
方法。它更新得很好,但显示ANR
消息。有没有其他方法可以实现它?
答案 0 :(得分:1)
你有两种方法可以做到 -