Is there any way to put a pushpin on an android map and when it's touched displays a popup with some extra info?
Asked
Active
Viewed 721 times
0
-
Sure there is. What have you tried so far? – Matt Ball Jan 05 '12 at 22:30
-
[Here](https://github.com/jgilfelt/android-mapviewballoons)'s a good place to start. – Marvin Pinto Jan 05 '12 at 22:31
-
Here's another link: http://stackoverflow.com/questions/3695634/mapview-adding-pushpins-on-touch – paulsm4 Jan 05 '12 at 22:35
1 Answers
0
You need to extend this http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/ItemizedOverlay.html.
public class CustomOverlay extends ItemizedOverlay<OverlayItem> {
private Context context;
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public CustomOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
this.context = context;
//after adding things to the overlay, call these:
setLastFocusedIndex(-1);
populate();
}
@Override
protected boolean onTap(int index) {
//called when an item is tapped
return true;
}
@Override
public boolean onTap (final GeoPoint p, final MapView mapV) {
boolean tapped = super.onTap(p, mapV);
if(!tapped){
//you can use this to check for other taps on the custom elements you are drawing
}
return true;
}
@Override
public void draw(Canvas canvas, MapView mapV, boolean shadow){
if(!shadow)
// if you have a custom image you may not want the shadow to be drawn
super.draw(canvas,mapV,shadow);
if(selected != null) {
// selected just means that something was clicked
// it isn't defined in this example
Projection projection = mapV.getProjection();
Point drawPoint = projection.toPixels(selected.getPoint(), null);
//get coordinates so you can do your drawing code afterward
}
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
}
This is a very rough sketch of what you need to do. Hope this helps.

Joru
- 4,406
- 1
- 19
- 13