4

可能重复:
将地图图钉添加到 Google Map Android 的最佳方式

如何添加图钉,如果单击显示带有信息地址或城市的 balon,我在 google maps API android 中有自定义 getOverlay()。

在我的代码下面:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_map);

    mapView = (MapView) findViewById(R.id.map_view);
    GeoPoint gpStart = new GeoPoint((int) (-6.31689 * 1E6),
            (int) (106.74040 * 1E6));

    GeoPoint gpEnd = new GeoPoint((int) (-6.29729 * 1E6),
            (int) (106.78386 * 1E6));

    Route r = direction(gpStart, gpEnd);
    RouteOverlay rOverlay = new RouteOverlay(r, Color.RED);
    mapView.getOverlays().add(rOverlay);
    mapView.getController().animateTo(gpStart);
    mapView.getController().setZoom(15);
    mapView.setBuiltInZoomControls(true);
}

我的代码已编辑,上面的代码我从这里获得并为我工作,但未在位置上显示图钉。如果代码是谷歌地图 V1 的标准,我知道要放置 pin 至极。只需添加覆盖。但我的问题是我从 json 数组中获取地图。所以我想在位置(地理点)中添加引脚,如果我点击我会得到信息地址。

谢谢。

4

1 回答 1

12

如果您使用的是Google Maps Android API v2,您应该这样做,这里记录了它。

private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
    .position(new LatLng(0, 0))
    .title("Hello world"));
于 2013-01-25T10:00:36.243 回答