使用 google 地图 api 时出错

Error while using google map api

我在使用 google 地图 api 时遇到以下错误。我是 运行 我在本地主机上的应用程序,所以我没有在 google 地图上注册它。我也搜索了其他一些解决方案并尝试了所有但仍然得到相同的结果。

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:我必须实现一个功能,如果我们 select 像加利福尼亚这样的城市,地图就会开始指出那个城市(加利福尼亚)。所以,如果可能的话,也告诉我这些的一些解决方案。 提前致谢。

如错误所述“...或该站点未被授权使用它”。您不能在本地主机上使用 API KEY。相反,对于 localhost 使用 Google Maps Api 而没有 API KEY:

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