code to add markers to map using android google maps v2

后端 未结 3 1062
逝去的感伤
逝去的感伤 2020-12-03 08:12

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 mark

3条回答
  •  旧时难觅i
    2020-12-03 08:32

    I'm guessing the issue is that you are multiplying your latitude/longitude values by 1E6 instead of dividing them by 1E6. If your stored values came from GeoPoints, that might be your issue. Otherwise, the way you are adding the Markers is fine and should work.

    i.e. the lat/lng values you pass to new LatLng() should look like 45.4,-95.5 NOT 45400000,-95500000

    Check out the following code:

    //mMap is a GoogleMap and point is a GeoPoint
    this.mMap.addMarker(getMarker(point, drawableId))
    

    ...

    public MarkerOptions getMarker(GeoPoint point, int drawableId)
    {
        return new MarkerOptions()
        .position(new LatLng(point.getLatitudeE6() / 1000000.0, point.getLongitudeE6() / 1000000.0))
        .icon(BitmapDescriptorFactory.fromResource(drawableId));
    }
    

提交回复
热议问题