[GOOGLE/API] 구글 API 지도 클릭, 주소 알아내기
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<div id="map" style="width:730px; height:500px;"><br /></div>
<script type="text/javascript">
<!--
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: new google.maps.LatLng(37.564615,126.98420299999998),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
google.maps.event.addListener(map, 'click', function(mouseEvent) {
getAddress(mouseEvent.latLng);
});
function getAddress(latlng) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
latLng: latlng
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0].geometry) {
var address = results[0].formatted_address.replace(/^日本, /, '');
new google.maps.InfoWindow({
content: address + "<br />(Lat, Lng) = " + latlng
}).open(map, new google.maps.Marker({
position: latlng,
map: map
}));
}
} else if (status == google.maps.GeocoderStatus.ERROR) {
alert("ERROR");
} else if (status == google.maps.GeocoderStatus.INVALID_REQUEST) {
alert("INVALID_REQUEST");
} else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
alert("OVER_QUERY_LIMIT");
} else if (status == google.maps.GeocoderStatus.REQUEST_DENIED) {
alert("REQUEST_DENIED");
} else if (status == google.maps.GeocoderStatus.UNKNOWN_ERROR) {
alert("UNKNOWN_ERROR");
} else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
alert("ZERO_RESULTS");
} else {
alert(status);
}
});
}
//-->
</script>