GOOGLE MAPS API - PROBLEMS WITH CLASS GLATLNGBOUNDS

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 1722  View(s)
Ratings:
Rate this:

Hi Everyone!

I am having some trouble with the Google Maps API. I have an array which holds a ojbect I created to store points.

My array and class:

var tPoints = [];   
function tPoint(name) {
        var id = name;
        var points = [];
        var pointsCount = 0;
        ...
        this.getHeadPoint = function() { return points[pointsCount-1]; }
    }
tPoint holds an array of GLatLng points. I want to write a function to return a GLatLngBounds object which is extended from the current map bounds to show

all the HeadPoints.

Heres what I have so far..

function getBounds() {
    var mBound = map.getBounds();
    for (var i = 0; i < tPoints.length; i++) {
     alert(mBound.getSouthWest().lat() + "," + mBound.getSouthWest().lng());
     alert(mBound.getNorthEast().lat() + "," + mBound.getNorthEast().lng());
            currPoint = trackMarkers[i].getHeadPoint();       
            if (!mBound.containsLatLng(currPoint)) {
                mBound.extend(currPoint);
            }
        }
    return mBound;
}
Which returns these values for the alert. (Generally over the US)
"19.64258,NaN"
"52.69636,NaN"
"i=0"
"19.64258,NaN"
"52.69636,-117.20701"
"i=1"

I don't know why I am getting NaN back. When I use the bounds to get a zoom level I think the NaN value is causing the map.getBoundsZoomLevel(bounds) to

return 0 which is incorrect. Am I using GLatLngBounds incorrectly?

Thanks in advance

 

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Google Maps API - Problems with class GLatLngBounds

    Hi Ankita!

    The Google maps sample is using this way

    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest();
    var northEast = bounds.getNorthEast();
    var lngSpan = northEast.lng() - southWest.lng();
    var latSpan = northEast.lat() - southWest.lat();


    The SouthWest/NorthEast bounds into a variable before attempting to get the individual lng/lat (Longitude/latitude)coordinates.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!