---
title: "Google Maps API - Problems with class GLatLngBounds"  
description: "Google Maps API - Problems with class GLatLngBounds"  
author: "Anonymous User"  
published: 2013-02-13  
updated: 2013-02-13  
canonical: https://www.mindstick.com/forum/600/google-maps-api-problems-with-class-glatlngbounds  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# Google Maps API - Problems with class GLatLngBounds

Hi Everyone!

I am having some trouble with the [Google Maps](https://www.mindstick.com/articles/12399/google-maps-updated-with-india-specific-features) API. I have an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) which holds a ojbect I created to [store](https://www.mindstick.com/articles/13125/tips-to-increase-sales-of-your-woocommerce-store) points.

My array and [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp):

var tPoints = []; \
[function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) 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](https://www.mindstick.com/forum/327/sum-textbox-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](https://www.mindstick.com/forum/34179/i-am-getting-error-while-assigning-the-data-to-the-array-list) NaN back. When I use the bounds to get a zoom level I think the NaN [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) is causing the map.getBoundsZoomLevel(bounds) to

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

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by AVADHESH PATEL

Hi Ankita!

The [Google](https://www.mindstick.com/articles/43833/google-lighthouse-and-how-is-it-changing-the-way-we-development-and-design-websites) 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.


---

Original Source: https://www.mindstick.com/forum/600/google-maps-api-problems-with-class-glatlngbounds

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
