如果不需要很精确的值,可以根据map的bounds自己计算(bias under 1%):
<!DOCTYPE html>
<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var map;
function initialize() {
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng(33.397, -81.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions
);
google.maps.event.addListener(map, 'click', function(event) {
document.getElementById('latMap').value = event.latLng.lat();
document.getElementById('lngMap').value = event.latLng.lng();
});
}
function mapDivClicked (event) {
var target = document.getElementById('map_canvas'),
posx = event.pageX - target.offsetLeft,
posy = event.pageY - target.offsetTop,
bounds = map.getBounds(),
neLatlng = bounds.getNorthEast(),
swLatlng = bounds.getSouthWest(),
startLat = neLatlng.lat(),
endLng = neLatlng.lng(),
endLat = swLatlng.lat(),
startLng = swLatlng.lng();
document.getElementById('posX').value = posx;
document.getElementById('posY').value = posy;
document.getElementById('lat').value = startLat + ((posy/350) * (endLat - startLat));
document.getElementById('lng').value = startLng + ((posx/500) * (endLng - startLng));
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas" onclick="mapDivClicked(event);" style="height: 350px; width: 500px;"></div>
x: <input id="posX" />
y: <input id="posY" />
lat: <input id="lat" />
lng: <input id="lng" />
<div />
lat from map: <input id="latMap" />
lng from map: <input id="lngMap" />
</body>
</html>