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
}开发者_JS百科;
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
}
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.
var mapZoom = mapInfo[0][2];
精彩评论