首页 > 解决方案 > 谷歌地图“仅用于开发目的”

问题描述

我的谷歌地图显示不正确。它显示“仅用于开发目的”,谷歌说我需要创建并启用一个计费帐户并创建一个 API 密钥。我已经这样做了,但是我需要在代码中更改或添加一些东西吗?

	// Get the HTML DOM element that will contain your map
	// We are using a div with id="map" seen below in the <body>
	var mapElement = document.getElementById('map');

	var map = new google.maps.Map(mapElement, mapOptions);
	var image = 'http://filmservice.no/wp-content/themes/filmservice16/img/ikon/map-marker.png';
	var marker = new google.maps.Marker({
		position: new google.maps.LatLng(59.969826, 10.905725),
		animation: google.maps.Animation.DROP,
		map: map,
		icon: image,
		title: 'Filmservice AS'
	});
	
function toggleBounce() {
  if (marker.getAnimation() !== null) {
    marker.setAnimation(null);
  } else {
    marker.setAnimation(google.maps.Animation.BOUNCE);
  }
}

标签: javascript

解决方案


您需要进行的更改实际上是在您的 HTML 标记中,其中包含 google maps API 脚本:

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>

有关更多信息,请参阅https://developers.google.com/maps/documentation/javascript/tutorial上的教程。


推荐阅读