tags:

views:

321

answers:

1

hi .. i have an old gmaps application using V2 and iam trying to update it to v3..

i have a really simple problem, but i cant fid a solution yet..

how can i strip the latitude and the longitude from the "event.latLng"? it is returning a point (), but i need only the lat alone and the long for itself ..

i cant get this to work !? any help is really appreciated !! thanks alot

+2  A: 

According to the API for MouseEvents, event.latLng contains a LatLng, not a Point. If this is the case then you can use the lat() and lng() methods to get the values separately. If event.latLng is actually a Point then you can directly access the coordinates using the x and y properties (not methods).

What type of listener is creating the event?


Edit: there's an example in the tutorial of how to do what you want. It looks like you're following this already. Did you remember to include the actual placeMarker() function declaration?

function placeMarker(location) {
    var clickedLocation = new google.maps.LatLng(location);
    var marker = new google.maps.Marker({
        position: location, 
        map: map
    });
    map.setCenter(location);
}

Or are you not interested in placing a marker, and just want to get the lat and lng values? In that case, all you need is:

google.maps.event.addListener(map, 'click', function(event) {
    var myLatLng = event.latLng;
    var lat = myLatLng.lat();
    var lng = myLatLng.lng();
}
Matt Ball
hallo ..iam trying the following google.maps.event.addListener(map, \'click\', function(event) { placeMarker(event.latLng); });i just need to extract the lat and lon from this
gmapsuser
thanks a lot ...that did the trick ..
gmapsuser
Glad to hear it. Which thing did you need to fix?
Matt Ball