code to add markers to map using android google maps v2

Use the Marker Class

An icon placed at a particular point on the map’s surface. A marker icon is drawn oriented against the device’s screen rather than the map’s surface; i.e., it will not necessarily change orientation due to map rotations, tilting, or zooming.

A marker has the following properties:

Anchor

The point on the image that will be placed at the LatLng position of the marker. This defaults to 50% from the left of the image and at the bottom of the image.

Position

The LatLng value for the marker’s position on the map. You can change this value at any time if you want to move the marker.

Title

A text string that’s displayed in an info window when the user taps the marker. You can change this value at any time.

Snippet

Additional text that’s displayed below the title. You can change this value at any time.

Icon

A bitmap that’s displayed for the marker. If the icon is left unset, a default icon is displayed. You can specify an alternative coloring of the default icon using defaultMarker(float). You can’t change the icon once you’ve created the marker.

Drag Status

If you want to allow the user to drag the marker, set this property to true. You can change this value at any time. The default is true.

Visibility

By default, the marker is visible. To make the marker invisible, set this property to false. You can change this value at any time.

GoogleMap map = ... // get a map.
   // Add a marker at San Francisco.
   Marker marker = map.addMarker(new MarkerOptions()
       .position(new LatLng(37.7750, 122.4183))
       .title("San Francisco")
       .snippet("Population: 776733"));

Leave a Comment