RSS

Get Address by postcode(Google Geocoding API)

17 Jan

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: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: