Google Maps API v=2.133d、地図上をクリック。けっこう正確、日本に限らず世界で使えて便利。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Maps API: Reverse Geocoding</title>
<style type="text/css">
body { font-family: Arial, Verdana, sans-serif; font-size: 13px; }
#map_canvas img { cursor: crosshair; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&hl=en&v=2.133d&key=YOUR-KEY"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
var marker;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37, 135.0), 5);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl(true));
geocoder = new GClientGeocoder();
GEvent.addListener(map, "click", clicked);
}
}
function clicked(overlay, latlng) {
if (latlng) {
geocoder.getLocations(latlng, function(addresses) {
if(addresses.Status.code != 200) {
alert("reverse geocoder failed to find an address for " + latlng.toUrlValue());
}
else {
map.clearOverlays();
address = addresses.Placemark[0];
marker = new GMarker(latlng, {draggable: true});
map.addOverlay(marker);
point2address();
GEvent.addListener(marker, "dragstart", function() {
map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", point2address);
}
});
}
}
function point2address(flag) {
point = marker.getPoint();
geocoder.getLocations(point, function(addresses) {
if(addresses.Status.code != 200) {
alert("reverse geocoder failed to find an address for " + point.toUrlValue());
}
else {
address = addresses.Placemark[0];
var myHtml = '<b>Reversed Geocoded Address:<\/b><br/>'+address.address + '<br/>' +
'<b>Coordinates (lat, lng):<\/b><br/>' + point.toUrlValue();
if (flag == 'plus original address') {
myHtml = '<b>Original Address:<\/b><br/>'+document.frm.address.value + '<br/>' +
'<b>Coordinates (lat, lng):<\/b><br/>' + point.toUrlValue() + '<br/><br/>' +
myHtml;
}
marker.openInfoWindow( myHtml);
}
});
}
function addCoordsToMap(response) {
map.clearOverlays();
if (!response || response.Status.code != 200) {
alert('Address not found');
}
else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
marker = new GMarker(point, {draggable: true});
map.setCenter(point, 15);
map.addOverlay(marker);
point2address("plus original address");
GEvent.addListener(marker, "dragstart", function() {
map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", point2address);
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLocations(address,addCoordsToMap)
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<form action="" name="frm" onsubmit="showAddress(this.address.value); return false">住所:
<input type="text" size="32" name="address" value="" />
<input type="submit" value="検索" /> ※アイコンは Draggable
</form>
<div id="map_canvas" style="width: 560px; height: 360px; border: 1px solid #666666; margin-top: 4px;">Loading...</div>
</body>
</html>