Find latlng of open infowindow

325 views
Skip to first unread message

unxcolin

unread,
Aug 14, 2010, 2:55:38 PM8/14/10
to Google Maps JavaScript API v3
I'm trying to find the latitude and longitude of the infowindow that
just opened, as I want to pan the map to centre on that point.

I'm actually using infobox not infowindow but that shouldn't make a
difference. http://code.google.com/p/google-maps-utility-library-v3/

google.maps.event.addListener(infobox, 'domready', function() {
var lat = latitude of opened infobox;
var lng = longitude of opened infobox;
$(".map_box").click(function(lat, lng) {
var myLatLng = new google.maps.LatLng(lat, lng);
map.panTo(myLatLng);
});
});

Any ideas on how I would get these values?

Site: http://bit.ly/d22gZo

Thanks

geoco...@gmail.com

unread,
Aug 14, 2010, 4:00:40 PM8/14/10
to Google Maps JavaScript API v3
On Aug 14, 11:55 am, unxcolin <colin.mei...@googlemail.com> wrote:
> I'm trying to find the latitude and longitude of the infowindow that
> just opened, as I want to pan the map to centre on that point.
>
> I'm actually using infobox not infowindow but that shouldn't make a
> difference.http://code.google.com/p/google-maps-utility-library-v3/
>
> google.maps.event.addListener(infobox, 'domready', function() {
>    var lat = latitude of opened infobox;
>    var lng = longitude of opened infobox;
>       $(".map_box").click(function(lat, lng) {
>          var myLatLng = new google.maps.LatLng(lat, lng);
>          map.panTo(myLatLng);
>       });
>
> });
>

> Any ideas on how I would get these values?

I think you are asking the wrong question. I usually use function
closure to keep the variable values I need for the infowindow/
infobox.

What is causing the infowindow/box to open?

>
> Site:http://bit.ly/d22gZo

Your page has serious problems in Chrome.

-- Larry

>
> Thanks

unxcolin

unread,
Aug 14, 2010, 4:45:01 PM8/14/10
to Google Maps JavaScript API v3
I'm not sure I follow. So I need get the lat/lng of the marker that
was clicked instead of finding it from? How would I keep the clicked
markers latlng alive for use in this function?

I think you may have viewed the site when I was uploading or messing
about. I'm developing on chrome (6.0.490.1 dev) and it's working well
for me. Should be okay now?

Thanks

unxcolin

unread,
Aug 15, 2010, 5:32:23 AM8/15/10
to Google Maps JavaScript API v3
Okay I'm much closer now. Well - it's working (on chrome at least).
This is all within createMarker:

google.maps.event.addListener(marker, 'click', function() {
infobox.setContent ("<div class=\"map_box\">Hello</div>");
infobox.open(map, marker);
google.maps.event.addListener(infobox, 'domready', function() {
$(".map_box").click(function() {
var myLatLng = new google.maps.LatLng(lat, lng);
map.panTo(myLatLng);
});
});
});

My only concern is that if I replace the panTo with an alert(lat) to
test this, then I receive an extra alert on each click (so first
marker click 1 alert popup - great. second marker click two alerts,
third marker click three alerts etc.), so I think something still
isn't quite right? I guess I need to clear the event listener after
each click somehow?

Thanks

happyhours

unread,
Aug 16, 2010, 5:17:49 AM8/16/10
to Google Maps JavaScript API v3
yeah just add

google.maps.event.clearListeners(infobox, 'domready');

after

map.panTo(myLatLng);

Cheers

unxcolin

unread,
Aug 16, 2010, 6:39:45 AM8/16/10
to Google Maps JavaScript API v3
Great, thank you : )
Reply all
Reply to author
Forward
0 new messages