javascript - jsFiddle 中的谷歌地图

标签 javascript google-maps jsfiddle

我正在尝试在 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 (这当然是调用初始化之外的)

Updated fiddle .

关于javascript - jsFiddle 中的谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13681917/

相关文章:

javascript - 我如何从本地主机 :5000 to localhost:3000 发送 http post 请求

javascript - 循环order.find、收集并向前端发送大量数据。方法不好?

javascript - 您已在此页面上多次包含 Google Maps JavaScript API。这可能会导致意外错误。使用 $.getScript() 调用时

javascript - Highcharts zIndex 十字准线问题

javascript - 如何在基于 jquery 的 jsfiddle 中使用 javascript?

javascript - 类型转换在数组中添加和减去数字索引值

javascript - Mongoose : Inserting JS object directly into db

javascript - 切换 Google map 标记

c# - 如何从 Google 静态 map API 获取图像

JavaScript let 绑定(bind)不应添加到全局对象中,浏览器、Node 和 jsfiddle 中的行为不同