用户从地图中选择位置以获取纬度和经度


Select location from map by user to get latitude and longitude

可能的重复项:
如何通过谷歌地图API检索纬度和经度?

我想在我的网站上添加一张地图,以我们的城镇为位置。它用于在我们的网站上列出镇上的商店。用户需要在地图上找到他们的商店位置。我们需要得到它们的纬度和经度位置。可以使用谷歌地图 api 吗?

将其添加到head

<script type="text/javascript" src="http://www.google.com/jsapi?autoload={'modules':[{name:'maps',version:3,other_params:'sensor=false'}]}"></script>

这在一个script标签中:

var geo;
function init() {
    var map_elem = document.getElementById('map-canvas');
    var map = new google.maps.Map(map_elem, {
        center: new google.maps.LatLng(0, 174.8859710),
        zoom: 2,
        minZoom: 2,
        maxZoom: 4,
        mapTypeId: google.maps.MapTypeId.HYBRID
    });
    geo = new google.maps.Geocoder();
    geo.geocode({
        address: 'New Zealand'
    }, function(e) {
        alert(e[0].geometry.location);
    });
}
google.maps.event.addDomListener(window, 'load', init);

根据需要进行调整。

请参阅地理编码服务 - Google Maps JavaScript API v3 - Google Developers。