2012-01-05 14 views
0

アンドロイドマップにプッシュピンを配置する方法はありますか?タッチされたときにポップアップに追加情報が表示されますか?アンドロイドマップ(選択可能なプッシュピン付き)

+0

あります。これまでに何を試しましたか? –

+0

[ここ](https://github.com/jgilfelt/android-mapviewballoons)はいい場所です。 –

+0

別のリンク:http://stackoverflow.com/questions/3695634/mapview-adding-pushpins-on-touch – paulsm4

答えて

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(); 
} 
} 

これは、行う必要があることの非常に概略的なスケッチです。お役に立てれば。

関連する問題