How to get the lat lng or position of a marker that is placed in googlemaps v2 and make a clickable link to googlemaps

StackOverflow https://stackoverflow.com/questions/23601010

Question

My code is as follows:

public void onInfoWindowClick(Marker marker) {

            // Get marker latLng

            marker.getPosition();

         Context context = getApplicationContext();

            SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); 

                    Intent i = new Intent(android.content.Intent.ACTION_SEND);

                    setLatitude();
                    setLongitude();

                    i.setType("text/plain");

                            + "http://maps.google.com/maps?q=loc:" + lat + "," + lng   );

In the link that is created I get this ( http://maps.google.com/maps?q=loc:null,null )

Why do I get null for lat and lng in text link.?

I have declared doubles for lat and lng at the head of the class.

The marker.getPosition(); should return a postion or pair of lat lng.

I can see that position in the info window.

Thanks for any help

Mike

Était-ce utile?

La solution

Your "lat" and "lng" variable are not declared nor instantiated.

This is the way to set them:

var lat = marker.getPosition().lat();
var lng = marker.getPosition().lng();

reference: https://developers.google.com/maps/documentation/javascript/reference#LatLng

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top