Adding multiple overlays on mapview dynamically

孤街醉人 提交于 2019-12-11 17:38:12

问题


I've a mapView on which I managed to get an overlay onLongPress with the help of GestureListener. What I actually want is, I want to add markers (with same icon) one by one. Like I want to mark different positions on map (not all at once). Any help with this would be great as am newbie with MapView and Overlays.


回答1:


Use ItemizedOverlay class to add drawable on specific longitudes and latitudes.

In your MapActivity write

GeoPoint your_point = (Provide geopoint information here);

Drawable drawable = this.getResources().getDrawable(R.drawable.your_point_image);

HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay( drawable, MapsActivity.this, mapView); GeoPoint point = new GeoPoint((int) (your_point.getLat() * 1E6), (int) (your_point.getLon() * 1E6));

OverlayItem overlayitem1 = new OverlayItem(your_point);

itemizedoverlay.addOverlay(overlayitem1); mapView.getOverlays().add(itemizedoverlay);

Where

HelloItemizedOverlay extends ItemizedOverlay{

public HelloItemizedOverlay(Drawable defaultMarker, Activity context, MapView mapView) { super(boundCenterBottom(defaultMarker)); mContext = context; this.mapView = mapView;

}

}

I did it this way and it works.



来源:https://stackoverflow.com/questions/14826824/adding-multiple-overlays-on-mapview-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!