在网站中显示Google地图时出错

时间:2017-06-14 08:54:56

标签: javascript html google-maps

我正在为我的网站使用html模板。谷歌地图在我的本地主机上工作正常但是当我在服务器上传它时它显示错误显示谷歌地图。

我尝试使用谷歌API密钥,但它仍然无法正常工作,并在屏幕上出现javascript错误。

请参阅随附的图片供您参考。

请告知我该怎么做。

http://www.cs.cornell.edu/people/pabo/movie-review-data/

1 个答案:

答案 0 :(得分:1)

<强> Maps.html

替换googlemaps API的密钥

<!DOCTYPE html>
<html>    
<body>    
<div id="map" style="width:100%;height:500px"></div>

<script>
function myMap() {
  var text="hello";
  var myCenter = new google.maps.LatLng(51.508742,-0.120850);
  var mapCanvas = document.getElementById("map");
  var mapOptions = {center: myCenter, zoom: 5};
  var map = new google.maps.Map(mapCanvas, mapOptions);
  var marker = new google.maps.Marker({position:myCenter});
  marker.setMap(map);
  google.maps.event.addListener(marker,'click',function() {
    var infowindow = new google.maps.InfoWindow({
      content: text
    });
  infowindow.open(map,marker);
  });
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=REPLACEKEY&callback=myMap"></script>
</body>
</html>