使用谷歌地图API时出错

时间:2015-12-18 07:47:39

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

我在使用google map api时遇到错误。我在localhost上运行我的应用程序,所以我没有在谷歌地图上注册它。我还搜索了其他一些解决方案并尝试了所有解决方案,但仍然保持不变。

This page was unable to display a Google Maps element. The provided Google API key is invalid or this site is not authorized to use it. Error Code: InvalidKeyOrUnauthorizedURLMapError

这是我的代码。

<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCUX7v9haBCA7Gv_YD9hEhj1m1nMBiZfqY&sensor=false">
</script>

<script>
function initialize()
{
var mapProp = {
  center:new google.maps.LatLng(51.508742,-0.120850),
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>

<div class="row" id="googleMap" style="width:500px;height:380px;">          </div>

PS:我必须实现一项功能,如果我们选择像加利福尼亚这样的城市而不是地图开始指出那个城市(加利福尼亚州)。所以,如果可能的话也告诉我一些解决方案。 提前致谢。

1 个答案:

答案 0 :(得分:1)

由于错误显示&#34; ...或此网站未被授权使用它&#34;。您无法在localhost上使用API​​ KEY。相反,对于localhost,请使用不带API KEY的Google Maps Api:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js"></script>
相关问题