我已经完成了以下Google Maps example的工作。有一个很大的通知说明如下
注意:不推荐使用登录功能。 Maps JavaScript API的版本3.27及更早版本继续支持登录地图,但未来版本将不再支持登录地图。请查看发布说明以获取更新。 (您可以订阅发行说明。)Maps JavaScript API的未来版本将继续支持使用信息窗口或SaveWidget将地点保存到Google地图的功能。
我尝试过使用SaveWidget和信息窗口,但它没有显示任何允许您保存地点的控件。它只有一个“在谷歌地图上查看”链接,可以将您带到谷歌地图。有没有办法通过按钮添加一个地方到您保存的地方,而无需重定向到谷歌地图?我认为他们对“拯救地方”的定义具有误导性......
在代码示例中,它还说明了这个
//When you add a marker using a Place instead of a location, the Maps
//API will automatically add a 'Save to Google Maps' link to any info
//window associated with that marker.
以下是显示“在Google地图上查看”链接的代码。
<!DOCTYPE html>
<html>
<head>
<title>Save a Place</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script>
// When you add a marker using a Place instead of a location, the Maps
// API will automatically add a 'Save to Google Maps' link to any info
// window associated with that marker.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 17,
center: {lat: -33.8666, lng: 151.1958}
});
var marker = new google.maps.Marker({
map: map,
// Define the place with a location, and a query string.
place: {
location: {lat: -33.8666, lng: 151.1958},
query: 'Google, Sydney, Australia'
},
// Attributions help users find your site again.
attribution: {
source: 'Google Maps JavaScript API',
webUrl: 'https://developers.google.com/maps/'
}
});
// Construct a new InfoWindow.
var infoWindow = new google.maps.InfoWindow({
content: 'Google Sydney'
});
// Opens the InfoWindow when marker is clicked.
marker.addListener('click', function() {
infoWindow.open(map, marker);
});
}
</script>
</head>
<body>
<div id="map"></div>
<script async defer
src="https://maps.googleapis.com/maps/api/js?v=3.27&key=YOUR_API_KEY&signed_in=true&callback=initMap">
</script>
</body>
</html>