I created a working google map that I am now trying to have auto zoom out so all the points fit.
When I added:
var bounds = new google.maps.LatLngBo
This error also seems to be raised when you set NaN
as the value of zoom
.
map.setZoom(null) // => nothing happens
map.setZoom(undefined) // => nothing happens
map.setZoom(NaN) // => error!
I used google map plugin: http://code.google.com/p/jquery-ui-map/ I found myself with the same problem, and as Ollie point, I had my json bad formatted. This was my json
mapObj=
[
{
"latitude": 57.797333,
"longitude": 12.050211,
"title": "Angered",
"content": "Representing :)"
},
{
"latitude": 57.696995,
"longitude": "11.9865",
"title": "Gothenburg",
"content": "Swedens second largest city"
}
]
Because of that longitude written as a string, I was getting that error.
SOLVED: Having all coordinates as numbers.!
To add the map (assuming local json, if not refer to reference link):
$('#map_canvas').gmap().bind('init', function() {
$.each( mapObj, function(i, marker) {
$('#map_canvas').gmap('addMarker', {
'position': new google.maps.LatLng(marker.latitude, marker.longitude),
'bounds': true
}).click(function() {
$('#map_canvas').gmap('openInfoWindow', { 'content': marker.content }, this);
});
});
});
Setting map center to a not supported lat/long also produces this error.
I've just run into the same exception, it turned out to be that the longitude passed into "new google.maps.LatLng" was undefined.
map.fitBounds(bounds);
is not receiving latitude/longitude or both.