Google maps api 3 谷歌地图异步
我有一个GoogleMaps脚本,我正在使用它,它可以很好地使用带有脚本标记的GoogleMaps,但是我想异步加载它,并且在进行更改时遇到了困难。这就是我目前拥有的:Google maps api 3 谷歌地图异步,google-maps-api-3,asynchronous,Google Maps Api 3,Asynchronous,我有一个GoogleMaps脚本,我正在使用它,它可以很好地使用带有脚本标记的GoogleMaps,但是我想异步加载它,并且在进行更改时遇到了困难。这就是我目前拥有的: //<![CDATA[ $(window).load(function(){ var locations = [ [ "850 Boylston Street", "Chestnut Hill, MA 02467", "42.326435", "-71.149499" ], [ "Subway Brookline Vil
//<![CDATA[
$(window).load(function(){
var locations = [
[
"850 Boylston Street",
"Chestnut Hill, MA 02467",
"42.326435",
"-71.149499"
],
[
"Subway Brookline Village",
"Green Line, D",
"42.33279",
"-71.11630"
],
[
"Shuttle Brookline Village",
"10 Brookline Place",
"42.33262",
"-71.116439"
],
[
"Subway Chestnut Hill",
"Green Line, B",
"42.338164",
"-71.153164"
],
[
"Subway Cleveland Circle",
"Green Line, C",
"42.336145",
"-71.149323"
],
[
"Subway Reservoir",
"Green Line, D",
"42.335132",
"-71.148762"
],
[
"Bus 51 Reservoir",
"Pick up from Subway",
"42.335021",
"-71.148988"
],
[
"Bus 51 Route 9",
"Drop off Route 9",
"42.326499",
"-71.142588"
],
[
"75 Francis Street",
"Boston, MA 02115",
"42.33619",
"-71.10705"
],
[
"Shuttle Longwood",
"Shapiro Building",
"42.33603",
"-71.10779"
],
[
"Subway Longwood",
"Green Line, D",
"42.34113",
"-71.11044"
],
[
"Subway Brigham Circle",
"Green Line, E",
"42.33422",
"-71.10455"
],
[
"Parking Garage",
"70 Francis Street",
"42.33422",
"-71.10455"
],
[
"20 Patriots Place",
"Foxboro, MA 02035",
"42.09254",
"-71.26629"
]
];
gmarkers = [];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 16,
center: new google.maps.LatLng(42.326435, -71.149499),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl:false
});
var infowindow = new google.maps.InfoWindow();
function createMarker(latlng, html) {
var marker = new google.maps.Marker({
position: latlng,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(html);
infowindow.open(map, marker);
});
return marker;
}
for (var i = 0; i < locations.length; i++) {
/* alert("location:"+
locations[i][0]+":"+locations[i][2]+","+locations[i][3]);
*/
gmarkers[locations[i][0]]=
createMarker(new google.maps.LatLng(locations[i][2], locations[i][3]), locations[i][0]
+ "<br>" + locations[i][1]);
}
/*
$(function() {
$('#locations h3 a').each(function() {
$(this).on('click', function() {
google.maps.event.trigger(marker, 'click');
})
});
});
*/
});//]]>
//
您有两个选择
<script type="text/javascript" src="http://www.google.com/jsapi"> </script>
HTH
var映射;
函数初始化(){
var mapOpt={
/*这是一个很好的例子*/
中心:新google.maps.LatLng(42,12),
缩放:15,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“谷歌地图”),mapOpt);
}
…在html中引用元素“
”Google map始终是异步加载的,在这种情况下,异步加载是什么意思?嗯,你确定因为Google map api有一节专门介绍异步加载的内容,他们似乎认为这是不同的吗?而不是通过放置
google.load("maps","3.9", {"other_params":"sensor=false"});
<script type="text/javascript">
var map;
function initialize() {
var mapOpt = {
/* le coordinate di partenza si possono impostare dal db */
center: new google.maps.LatLng(42, 12),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"), mapOpt);
}