Question

I'm using google maps to mark several positions which is updated at equal time intervals. There is no problem with markers they working fine. But when updating the markers and when the map is zoomed in, the markers disappears and takes long time to get marked in the map. Its looks as if the people had disappeared all of a sudden.

I'm using counter class to call update marker worker thread at equal intervals.

Counter class

     public class MyCount extends CountDownTimer{

    public MyCount(long millisInFuture, long countDownInterval) {
    super(millisInFuture, countDownInterval);
    }

    @Override
    public void onFinish() {
        new MapUpdater().execute("");
        resetTimer();                 
    }

    public void resetTimer()
    {
        counter = new MyCount(5000,1000);
            counter.start();
    }

    @Override
    public void onTick(long millisUntilFinished) {
    }

 }

MapUpdater Async task

     private class MapUpdater extends AsyncTask<String, Integer, String> {
   @Override
   protected void onPreExecute() {
      Log.d("ASYN", "STARTED");
      map.invalidate();
         itemizedoverlay.doPopulate();
      }
   @Override
   protected String doInBackground(String... params) {
       updatePosition();
       return "finished";
   }

   @Override
   protected void onProgressUpdate(Integer... values) {
      super.onProgressUpdate(values);
   }

   @Override
   protected void onPostExecute(String result) {
         super.onPostExecute(result);
         itemizedoverlay.doPopulate();
         Log.d("ASYN", "ENDED");
   }

}

updatePosition() method

     public void updatePosition()
     {
    try{
                lat_coordinates[]= CustomHttpClient.executeHttpPost("http://10.0.2.2/return_coord.php", postParameters);
                lng_coordinates[]= CustomHttpClient.executeHttpPost("http://10.0.2.2/return_coord.php", postParameters);
     }catch (Exception e) {
            e.printStackTrace();
     }
            itemizedoverlay.removeAllOverlay();
            itemizedoverlay.doPopulate();

             try{
                for(int i=0; i<lat_coordinates.length; i++)
                 {
                     GeoPoint point = new GeoPoint((int)(lat_coordinates[i]*1E6),(int)(lng_coordinates[i]*1E6));
                     try {
                        addresses = geocoder.getFromLocation(lat_coordinates[i],lng_coordinates[i], 1);
                    } catch (NumberFormatException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Log.d("update", "no format exception");
                    }catch (Exception e) {
                        Log.d("update", e.toString());
                    }
                     overlayitem = new OverlayItem(point,"title",addresses.get(0).getAddressLine(0));
                     itemizedoverlay.addOverlay(overlayitem);
                 }
             }catch(NullPointerException e){
                 e.getStackTrace();

             }
             finally{
                overlayList.add(itemizedoverlay);
         }

}

Any suggestions? It take long time to update that it spoils the entire application.

Thanks

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top