Is there any diference between .getPosition() and .lat() .long() methods?

2,152 views
Skip to first unread message

Daniel Montenegro

unread,
Aug 15, 2012, 7:12:46 PM8/15/12
to google-map...@googlegroups.com
Hi there, Google Maps folks!

Well, this is the question:

Is there any diference between .getPosition() and .lat() .long() methods?

I need to have the marker coordinates on the screen as I click on it. So I thought in a event like this:

google.maps.event.addListener(marker, 'click', function() {
        document.getElementById('coords').value = marker.getPosition();
    });

To work along such a form:

<input type="textbox" id="coords">

But unfortunnelly, Firebug is giving me a message error, saying that marker is not defined.

Any help would be great!

Daniel



geoco...@gmail.com

unread,
Aug 15, 2012, 9:57:56 PM8/15/12
to Google Maps JavaScript API v3
On Aug 15, 4:12 pm, Daniel Montenegro <dmontenegr...@gmail.com> wrote:
> Hi there, Google Maps folks!
>
> Well, this is the question:
>
> Is there any diference between .getPosition() and .lat() .long() methods?

On what object? The getPosition method typically returns a
google.maps.LatLng object.

A google.maps.LatLng object tends to have .lat() and .lng() methods
which return the floating point values of those coordinates.

>
> I need to have the marker coordinates on the screen as I click on it. So I
> thought in a event like this:
>
> google.maps.event.addListener(marker, 'click', function() {
>         document.getElementById('coords').value = marker.getPosition();
>     });

That should work assuming marker is defined as a google.maps.Marker
object and is in scope.

>
> To work along such a form:
>
> <input type="textbox" id="coords">
>
> But unfortunnelly, Firebug is giving me a message error, saying that marker
> is not defined.

That is an entirely different problem. Most likely your "marker"
variable is not in the global scope (it is probably local to some
function).

-- Larry
Reply all
Reply to author
Forward
0 new messages