开发者

How to implements Marker Lazy Loading from URL in MapView overlay

I have activity which can show overlay. This overlay have markers which gets from web.

How开发者_C百科 can I implements lazy loading from URL for this markers?

Thx, Igor


What you need to do is get create an AsyncTask to retrieve your data. Once the async task executes and you have the data the UI thread will call onPostExecute(). In your onPostExecute() method you will add your data to your map view the same you would in the example android code.

Here's the a mostly complete example. You should be able to fill in the holes with this.

    public class SomeActivity extends MapActivity {
        private MapView mYourMapView;

        protected void onCreate(Bundle yourbundle){
          super.onCreate(yourbundle);
          setContentView(R.layout.yourcontentview);

          mYourMapView = (MapView)findViewById(R.id.yourmapviewid);

          GetYourDataTask task = new GetYourDataTask(mYourMapView);
          task.execute();
        }
     }

     public class GetYourDataTask extends AsyncTask<Void, Void, Void>{
           private MapView mView;
           private List<Items> mYourItemsFromInternetSource;

           public GetYourDataTask(MapView view){
              this.mView = view;
           }

           protected Void doInBackground(Void... params){
                .....get some data from internets
                mYourItemsfromInternetSoruce = something you got from internet;
                return null;
           }

           protected Void onPostExecute(){
                YourOverlay overlay = new YourOverlay(mYourItemsFromInterSource);
                mView.getOverlays().add(overlay);
           }
    }

    public YourOverlay extends ItemizedOverlay<OverlayItem>{
              private List<OverlayItem> mItems;
              public YourOverlay(List<Item> itemsFromInternet)[
                     super(boundCenterBottom(someContext.getResources().getDrawable(R.drawable.map_pin)));
                     //for your items create overlay items then
                     List<OverlayItem> createdItems = someConvertFunction(itemsFromInternet);
                     for(OverlayItem item: createdItems){
                          mItems.add(item);
                          populate();
                     }
               }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜