无法使用Google map javascript api v3在Google地图上设置多个标记 [英] Not able to set multiple markers on the Google maps using Google map javascript api v3
本文介绍了无法使用Google map javascript api v3在Google地图上设置多个标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在地图上放置多个标记,但我得到的地图没有设置标记。
i want to place multiple markers on the map but I'm getting a map with no markers set.
<script type="text/javascript">
var map;
var i;
window.onload=function()
{
var mapOptions = {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(59.32522, 18.07002)
};
map = new google.maps.Map(document.getElementById("map"),mapOptions);
var bounds = new google.maps.LatLngBounds();
var places =[];
places.push(google.maps.LatLng(40.756,-73.986));
places.push(google.maps.LatLng(59.32522, 18.07002));
places.push(google.maps.LatLng(37.775,-122.419));
places.push(google.maps.LatLng(47.620,-122.347));
places.push(google.maps.LatLng(-22.933,-43.184));
for(i=0; i<places.length;i++)
{
var marker= new google.maps.Marker({position:places[i],map: map,title:'place Number'+i});
bounds.extend(places[i]);
}
map.fitBounds(bounds);
}
</script>
推荐答案
您需要更改所有看起来像这样的行:
You need to change all your lines that look like this:
places.push(google.maps.LatLng(40.756,-73.986));
看起来像这样:
To look like this:
places.push(new google.maps.LatLng(40.756,-73.986));
以上是您的代码,并进行了这些修改。它为我工作。尝试一下:
Here's your code above with these modifications. It's working for me. Try it:
<script type="text/javascript">
var map;
var i;
window.onload=function()
{
var mapOptions = {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(59.32522, 18.07002)
};
map = new google.maps.Map(document.getElementById("map"),mapOptions);
var bounds = new google.maps.LatLngBounds();
var places =[];
places.push(new google.maps.LatLng(40.756,-73.986));
places.push(new google.maps.LatLng(59.32522, 18.07002));
places.push(new google.maps.LatLng(37.775,-122.419));
places.push(new google.maps.LatLng(47.620,-122.347));
places.push(new google.maps.LatLng(-22.933,-43.184));
for(i=0; i<places.length;i++)
{
var marker= new google.maps.Marker({position:places[i],map: map,title:'place Number'+i});
bounds.extend(places[i]);
}
map.fitBounds(bounds);
}
</script>
这篇关于无法使用Google map javascript api v3在Google地图上设置多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文