Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

code to add markers to map using android google maps v2

I have lat&long values from database.how to display markers based on lat &long values using android google map api v2.In original android google maps,we display markers based on concept itemoverlay. In v2,I dont know how to display markers.

    dbAdapter.open();
        Cursor points = dbAdapter.clustercall(Btmlft_latitude, toprgt_latitude,
                Btmlft_longitude, toprgt_longitude, gridsize1);
        int c = points.getCount();
        Log.d("count of points", "" + c);

        if (points != null) {
            if (points.moveToFirst()) {
                do {

                    int latitude = (int) (points.getFloat(points
                            .getColumnIndex("LATITUDE")) * 1E6);
                    int longitude = (int) (points.getFloat(points
                            .getColumnIndex("LONGITUDE")) * 1E6);

                    mapView.addMarker(new MarkerOptions().position(
                            new LatLng(latitude, longitude)).icon(
                            BitmapDescriptorFactory.defaultMarker()));

                } while (points.moveToNext());

            }
        }
        points.close();
        dbAdapter.close();

That is mycode.I am getting lat&long values from database,but how to add markers based on lat &long values to map.

I read the android google maps api v2.In that have only give statically added data of markers

like image 711
Kumar Kalluri Avatar asked Jan 07 '13 11:01

Kumar Kalluri


People also ask

How do I add a marker to Google Maps Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.


1 Answers

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"));
like image 53
K_Anas Avatar answered Sep 22 '22 17:09

K_Anas