This reverse geo-coder will convert a point on a map to an address. In practice this means the nearest available address.
var geocoder;
var map;
function initialize()
{
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(54.55, -5.953);
var myOptions = {zoom: 11,center: latlng,mapTypeId:google.maps.MapTypeId.HYBRID,draggableCursor:'crosshair'}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, 'click',function(me){
codeLatLng(me.latLng);
});
}
function codeLatLng(latlng)
{
if (geocoder)
{
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
if (results[1])
{
document.getElementById("address").innerHTML=results[1].formatted_address;
}
else
{
document.getElementById("message").innerHTML="Geocoder failed due to: " + status;
document.getElementById("address").innerHTML="";
}
}
});
}
}
Hi, If you want the country instead of the full address use "place = response.Placemark[0]" then "place.address" and this should return the country name. This is what is being used on <a href="http://www.daftlogic.com/sandbox-click-for-country.htm">Click For Country</a>.
By Daft Logic on 3rd May 2008nice job there!
I'm wondering how difficult this will be to simply output the country...
When you zoom out of this version and click, it bugs out displaying several addresses
There's no need to create an account or provide unnecessary details. Just your comment.