Logic, but in a different way

Daft Logic

Google Maps Reverse Geocoder

Last Updated 6th December 2010

This reverse geo-coder will convert a point on a map to an address. In practice this means the nearest available address.

Feedback

Instructions

Javascript Used

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="";
}
}
});
}
}

Previous Comments For This Page

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 Click For Country.
By Daft Logic on 03/05/2008
nice 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
By Bitcloud on 23/04/2008

Add your own comment below and let others know what you think:

Comments :

Your Name (optional) :