RSS

Tag Archives: Address

Get Address by postcode(Google Geocoding API)

Sometimes we need the address against postcode or need postcode against address. Google geocoding API provides this way correctly.

Suppose you have a text box and a button

<input type=”text” name=”location” id=”location” />
<input type=”button” name=”show” value=”show address” id=”show-add” />

Then it can be done by following script. I used here geocode v3.

<script type=”javascript/text” >
$(‘#show-add’).click(function(){
var location = $(‘#location’).val();
getAddress(location);
});

function getAddress(location){
geocoder = new google.maps.Geocoder();
geocoder.geocode( { ‘address’: location }, function(results, status) {
if (status == ‘OK’) {
alert(results[0].formatted_address);

} else {

alert(“Geocode was not successful for the following reason: ” + status);
}
});
}

</script>

for more informaton see this link : http://code.google.com/apis/maps/documentation/geocoding/

We can do this by v2 too but in v2 api_key is needed.

function getAddress(location){
$.getJSON(“http://maps.google.com/maps/geo?q=”+location+”key=”+googleApi+”&sensor=false&output=json&callback=?&#8221;,function(data, textStatus){
$.each(data.Placemark, function(key, val) {
alert(val.address);
});
});
}

Advertisements
 
Leave a comment

Posted by on January 17, 2012 in API, javascript, jQuery

 

Tags: , , ,