Привет. Я пытаюсь показать 100 маркеров на картах Google, но когда мы отображаем маркеры на карте.Остановка прокрутки карты Google и приложение показывают ANR.Ниже мой код для отображения маркера на карте.Также API вызывает каждые 5 секунд, используя сервис.
Пожалуйста, что мы делаем не так.
if (getWorkerSummaryListResponse.getErrorCode() == 0) {
workerListList = getWorkerSummaryListResponse.getWorkerListList();
Log.d(TAG, "setData: " + workerListList.toString());
for (user.WorkerSummary workerBasicInfo : workerListList) {
userPosition = workerBasicInfo.getUserPosition();
workerAlarmStatus.get(workerBasicInfo.getUserAlarmStatus());
if (workerBasicInfo.getWorkerActiveStatus() == 1) {
if (!userPosition.toString().equalsIgnoreCase("")) {
if (!mOnlineWorkerList.contains(workerBasicInfo)) {
mOnlineWorkerList.add(workerBasicInfo);
}
userPosition.getGpsData().getLat();
userPosition.getGpsData().getLng();
markerOptions = new MarkerOptions();
markerOptions.icon(icon);
markerOptions.position(new LatLng(userPosition.getGpsData().getLat(), userPosition.getGpsData().getLng()));
markerOptions.title(workerBasicInfo.getWorkerInfo().getEmail());
// mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(userPosition.getGpsData().getLat(), userPosition.getGpsData().getLng())));
// mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(userPosition.getGpsData().getLat(), userPosition.getGpsData().getLng()), 12.0f));//where 14.0 is the zoom level
marker = mMap.addMarker(markerOptions);
marker.setTag(workerBasicInfo);
}
}
}
Сервисный код: ---
открытый класс MyService расширяет Сервис {
public static final int notify = 20000; //interval between two services(Here Service run every 5 seconds)
int count = 0; //number of times service is display
private Handler mHandler = new Handler(); //run on another Thread to avoid crash
private Timer mTimer = null; //timer handling
AuthorizeApp mAuthorizeApp;
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
mAuthorizeApp = AppManager.shareInstance(this).getAuthorizeApp();
if (mTimer != null) // Cancel if already existed
mTimer.cancel();
else
mTimer = new Timer(); //recreate new
mTimer.scheduleAtFixedRate(new TimeDisplay(), 0, notify); //Schedule task
}
@Override
public void onDestroy() {
super.onDestroy();
mTimer.cancel(); //For Cancel Timer
Toast.makeText(this, "Service is Destroyed", Toast.LENGTH_SHORT).show();
}
//class TimeDisplay for handling task
class TimeDisplay extends TimerTask {
@Override
public void run() {
// run on another thread
mHandler.post(new Runnable() {
@Override
public void run() {
// display toast
mAuthorizeApp.getRealTimeInstrumentInfo(new GetInstrumentListTask(getApplicationContext()));
}
});
}
}