Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to add pin to google maps [duplicate]

Possible Duplicate:
Best Way to Add Map Pins to Google Map Android

How to add pin and if clicked show balon with info address or city which I have custom getOverlay() in google maps API android.

Below my code:

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

My code have edited, Code in above i get from here and work for me, but not show pin on location. I know to put pin wich if code is standart from google maps V1. Just add overlay. But my problem is I get map from json array. So i want to add pin in location(geopoint) and if i click i get info address.

Thanks.

like image 695
Dave Jackson Avatar asked Dec 16 '22 14:12

Dave Jackson


1 Answers

If you're using the Google Maps Android API v2, which you should do, it's documented here.

private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
    .position(new LatLng(0, 0))
    .title("Hello world"));
like image 167
keyboardsurfer Avatar answered Jan 02 '23 13:01

keyboardsurfer