以下代码能够在单击时获取坐标。
但是,如何使用Google Maps API在地图上单击以获取地址、城市名称、区域名称或国家名称呢?
以下代码允许在单击时获取坐标。 但如何使用Google Maps API在地图上单击以获取地址、城市名称、区域名称或国家名称?
var myLatlng = new google.maps.LatLng(41.38,2.18);
var myOptions = { zoom: 13, center: myLatlng}
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
google.maps.event.addListener(map, 'click', function(event) {alert(event.latLng);});
html, body, #map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,places&ext=.js"></script>
<div id="map-canvas"></div>
event.latLng
通过地理编码器传递可能是一个选项。 - putvande