我正在尝试在 jsFiddle 中实现 Google map 来问另一个问题,但我看不到 map : http://jsfiddle.net/hashie5/aknYP/
我已经在资源中添加了 gmap 脚本
如何在 jsFiddle 中显示 map ?
function initialize() {
var myLatlng = new google.maps.LatLng(50.965049,5.484231);
var myOptions = {
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var contentString =
'<div id="infowindow">' +
'Galaconcert<br />' +
'Jaarbeurslaan 2-6<br />' +
'3690 Genk' +
'</div>'
;
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Galaconcert'
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map, marker);
});
}
最佳答案
如解释here “Add Resources”下红框:
Warning: jsFiddle is recognizing the type of the resource by the extension. If you want to use a dynamic resource please add a dummy GET variable i.e.
http://example.com/download/js/dynamically.js?somevar=somevalue&dummy=.js
. This will trick jsFiddle to recognize it as JavaScript resource.
因此,为了让 jsFiddle 识别 Google Maps API(确实没有 .js 扩展名),您需要将其添加为资源:http://maps.googleapis.com/maps/api/js?sensor=false&dummy=.js (这当然是调用初始化之外的)
关于javascript - jsFiddle 中的谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13681917/