James
James

Reputation: 17

Google Map API v3 - Invalid value for property <zoom>

Using Google Maps API v3, I’m trying to do something like below to set zoom. The problem is this would give:

Error: Invalid value for property <zoom>: 10

Any help appreciated, thanks.

var mapInfo = [ [-34.397],[150.644],[10] ];

function initialize() {
    var latlng = new google.maps.LatLng(mapInfo[0],mapInfo[1]);
    var mapZoom = mapInfo[2];
    var myOptions = {
        zoom: mapZoom,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
}

Upvotes: 0

Views: 5399

Answers (2)

skarE
skarE

Reputation: 5890

Change

var mapInfo = [ [-34.397],[150.644],[10] ];

to

var mapInfo = [-34.397, 150.644, 10];

Then your code should work.

The problem was that what you had was an array of arrays. The square brackets denotes an array so you were passing a array that contained the value instead of value the value itself.

Upvotes: 1

Vjy
Vjy

Reputation: 2135

var mapZoom = mapInfo[0][2];

Upvotes: 1

Related Questions