Google地图在本地显示,但在发布时不显示

时间:2017-03-20 13:49:54

标签: javascript google-maps

我有一个网络应用程序,可以根据来自数据库的pg查询动态设置的自定义标记来对大陆我们进行居中和缩放。地图在本地显示,但在我将其发布到我的服务器后却没有显示。我有一个api密钥,并已在谷歌开发控制台上确认了权限。

这是javascript:

function initMap() {

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 5,
      center: {lat: 39.350033, lng: -94.6500523}
    });

    // Do not actually need labels for our purposes, but the site_id is best if they are required.
    var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';



    // Add some markers to the map.
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {

if (xhr.readyState == 4) {
    var arr = JSON.parse(xhr.responseText);
    console.log(xhr.responseText);
    if(Array.isArray(arr)){
        showMarkers(arr);
    }
}
}
xhr.open('GET', 'markers.php', true);
xhr.send();

function showMarkers(locations){
var markers = locations.map(function(location, i) {
  return new google.maps.Marker({
    position: location,
    label: labels[i % labels.length]
  });
});

var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'});
}
  }

我对api键设置了限制 .rightmediasolutions.com /

以下是已发布的html的链接:http://www.rightmediasolutions.com/gs_chrome/map.html

1 个答案:

答案 0 :(得分:0)

进行了一些研究......为了使地图完全初始化,高度和宽度需要内联样式而不是链接样式表。