2012-01-05 58 views
0

有没有什么办法可以在android地图上放一个图钉,当它被触摸时显示一个额外的信息弹出?有可选图钉的Android地图

+0

当然有。你试过什么了? – 2012-01-05 22:30:35

+0

[这里](https://github.com/jgilfelt/android-mapviewballoons)是一个很好的开始。 – 2012-01-05 22:31:51

+0

这是另一个链接:http://stackoverflow.com/questions/3695634/mapview-adding-pushpins-on-touch – paulsm4 2012-01-05 22:35:33

回答

0

您需要扩大此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(); 
} 
} 

这是您需要做的非常粗略的草图。希望这可以帮助。