Question

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.

Was it helpful?

Solution

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.

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