Google Maps API - Problems with class GLatLngBounds

Total Post:183


 2236  View(s)
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)) {
    return mBound;
Which returns these values for the alert. (Generally over the US)

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. 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 = -;

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

      Modified On Mar-29-2018 10:52:23 PM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.