我试图使用谷歌地方api建立一个咖啡定位器应用程序

时间:2016-08-05 17:51:36

标签: google-maps google-maps-api-3 google-places-api

感谢帮助geocode我做了更改,但我仍然遇到同样的问题,我很抱歉给你带来了小错误,但是如果你有时间的话可能会发布下面的代码

 <html lang="en">
 	   <head>
 	   	    <meta charset="utf-8">
 	   	    <meta name="viewport" content="initial-scale1.0, user-scalable no">
 	   	    <script	type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBxa8x1c5vnQZr95sqld_ZYT_1hM7yVNxU"> 
 	   	   <script> var map;
 	   	    function initialize() {
  var center = new google.maps.LatLng(51.5044672, -0.0821554);
  map = new google.maps.Map(document.getElementById('map'), {
    center: center,
    zoom: 13
  });
}
google.maps.event.addDomListener(window, 'load', initialize);

html,
body,
#map {
  height: 100%;
  margin: 0px;
  padding;
  0px
}

<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map">
</div>
 	   	</style>
 	 </head>
 	 <body>
 	 	<div id="map">
 	 	</div>
 	</body>
 </html>

2 个答案:

答案 0 :(得分:0)

YouTube视频中的很多评论都说他们得到一个空白页面,也许你需要一个新的Google API密钥。

来源: https://developers.google.com/maps/documentation/javascript/get-api-key

答案 1 :(得分:0)

发布的代码中存在多个语法错误:

Uncaught SyntaxError: missing ) after argument list在这一行:

google.maps.event.addDomListener(window, 'load' initialize);

(在'加载'和初始化之间缺少“,”)

Uncaught TypeError: google.maps.latlng is not a constructor在这一行:

var center = new google.maps.latlng(51.5044672,-0.0821554);

(javascript区分大小写,正确的版本为LatLng而非latlng

此行上的

Uncaught TypeError: document.getelementById is not a functionUncaught TypeError: google.maps.map is not a constructor

map = new google.maps.map(document.getelementById('map'), {

(javascript区分大小写,正确的版本为getElementById而非getelementByIdgoogle.maps.map应为google.maps.Map

如果我修复了这些问题,我会得到一张地图(fiddle),但发布的代码中没有“咖啡定位器”功能。

代码段

function initialize() {
  var center = new google.maps.LatLng(51.5044672, -0.0821554);
  map = new google.maps.Map(document.getElementById('map'), {
    center: center,
    zoom: 13
  });
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map {
  height: 100%;
  margin: 0px;
  padding;
  0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map">
</div>