2012-01-06 11 views
0

私はlat、lng、およびテキストの一部のJSONオブジェクトを持っています。私はItemizedOverlayを使ってそれらの場所をGoogle Mapに追加しています。 Drawableオブジェクト(resディレクトリの単純なpng)である個々のマーカーで、すべての異なるOverlayItemを追加しています。android + google mapsマーカー

しかし、このマーカーは場所のテキストも含めて、もう少し意味のあるものにすることをおすすめします。そのテキストを取得することは問題ありませんが、場所やマーカーにどのように追加できますか?

私は独自のマーカーを作成する必要がありますか?osは、地図上にテキストを位置とともに表示することができる他のオブジェクトですか?すべてのポインタ?

+0

おそらくこれを試してみてください: http://stackoverflow.com/questions/6777022/how-to-drawan-overlay-with-buttons-text-and-image-on-a-google-map – goodm

答えて

1

これはチェックしてください....あなたは、次のパラメータ

geopoint = new GeoPoint((int) (Double.parseDouble(lat) * 1E6), (int)Double.parseDouble(lon) * 1E6)); 
myMapView.getOverlays().add(new DrawableMapOverlay(this,geopoint,R.drawable.map, name)); 

を追加する必要があなたの活動に
を、その後DrawableMapOverlayクラス

import com.google.android.maps.MapView; 
import com.google.android.maps.Overlay; 

public class DrawableMapOverlay extends Overlay { 

    private static final double MAX_TAP_DISTANCE_KM = 3; 
    // Rough approximation - one degree = 50 nautical miles 
    private static final double MAX_TAP_DISTANCE_DEGREES = MAX_TAP_DISTANCE_KM * 0.5399568 * 50; 
    private final GeoPoint geoPoint; 
    private final Context context; 
    private final int drawable; 
    private final String workerName; 
    /** 
    * @param context the context in which to display the overlay 
    * @param geoPoint the geographical point where the overlay is located 
    * @param drawable the ID of the desired drawable 
    */ 
    public DrawableMapOverlay(Context context, GeoPoint geoPoint, int drawable,String workerName) { 
    this.context = context; 
    this.geoPoint = geoPoint; 
    this.drawable = drawable; 
    this.workerName = workerName; 
    } 

    @Override 
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { 
    super.draw(canvas, mapView, shadow); 

    // Convert geo coordinates to screen pixels 
    Point screenPoint = new Point(); 
    mapView.getProjection().toPixels(geoPoint, screenPoint); 
    Paint paint = new Paint(); 
    // Read the image 
    Bitmap markerImage = BitmapFactory.decodeResource(context.getResources(), drawable); 
    paint.setStrokeWidth(1); 
    paint.setARGB(150, 000, 000, 000); 
    paint.setStyle(Paint.Style.STROKE); 
    // Draw it, centered around the given coordinates 
    canvas.drawBitmap(markerImage, 
     screenPoint.x - markerImage.getWidth()/2, 
     screenPoint.y - markerImage.getHeight()/2, null); 
    canvas.drawText(workerName, screenPoint.x- markerImage.getWidth()/2, screenPoint.y - markerImage.getHeight()/2 , paint); 
    return true; 
    } 

    @Override 
    public boolean onTap(GeoPoint p, MapView mapView) { 
    // Handle tapping on the overlay here 
    return true; 
    } 
} 

にそれは私では正常に動作している完璧なソリューションですプロジェクト。

関連する問題