LatLngBounds Array Values

1,358 views
Skip to first unread message

Chris Macdonald

unread,
Nov 29, 2010, 11:31:53 PM11/29/10
to google-map...@googlegroups.com
I've been trying to pass 5 markers to a map and have the map center around the points but am not able to get it to function for me anymore. This is my first time working with the V3 api so I'm not sure if I've done something wrong as well.

    var lat = new Array();
    var lng = new Array();
    lat[0] = 0;
    lat[1] = 1;
    lat[2] = 2;
    lat[3] = 3;
    lat[4] = 4;
    lat[5] = 5;
    lng[0] = 6;
    lng[1] = 7;
    lng[2] = 8;
    lng[3] = 9;
    lng[4] = 10
    lng[5] = 11;
    for (var i = 0; i < 5; i++) {
        var location = new google.maps.LatLng(lat[i], lng[i]);
        var marker = new google.maps.Marker({
            position: location,
            map: map
        });
        var j = i + 1;
        marker.setTitle(j.toString());
        var bounds = new google.maps.LatLngBounds(lat[i], lng[i]);
        map.fitBounds(bounds);
      }

Here's is a link: http://174.120.151.156/~crazychr/test2.html

I'm getting the following error message in firebug:

a.lat is not a function
http://maps.gstatic.com/intl/en_us/mapfiles/api-3/3/1b/main.js
Line 12

when I try that code, get only 2 markers and it doesn't zoom or center. When I change it to

var bounds = new google.maps.LatLngBounds(lat[0], lng[5]);

it displays all 5 but doesn't center or adjust the zoom.

Thanks for any help you can offer.

geoco...@gmail.com

unread,
Nov 30, 2010, 12:18:56 AM11/30/10
to Google Maps JavaScript API v3
> a.lat is not a functionhttp://maps.gstatic.com/intl/en_us/mapfiles/api-3/3/1b/main.js
> Line 12
>
> when I try that code, get only 2 markers and it doesn't zoom or center.
> When I change it to
>
> var bounds = new google.maps.LatLngBounds(lat[0], lng[5]);

http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds

LatLngBounds(sw?:LatLng, ne?:LatLng) Constructs a rectangle from the
points at its south-west and north-east corners.

That is not a valid call to the constructor for LatLngBounds...

-- Larry

Chris Macdonald

unread,
Nov 30, 2010, 1:16:46 AM11/30/10
to google-map...@googlegroups.com
In my old v2 code I had this (not directly, within some other loops, but similiar)

var bounds = new GLatLngBounds();
bounds.extend(point);
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

to center it around the points of the map.

I thought that function would select the furthest ne point and furthest sw point from the array value. This would then create the rectangle to show all the values within that.

geoco...@gmail.com

unread,
Nov 30, 2010, 1:20:38 AM11/30/10
to Google Maps JavaScript API v3
On Nov 30, 1:16 am, Chris Macdonald <thebluewal...@gmail.com> wrote:
> In my old v2 code I had this (not directly, within some other loops,
> but similiar)

That code is not the same. If you had done that in v3 it would have
worked.
Reply all
Reply to author
Forward
0 new messages