Sunday, April 3, 2011

Geocode Address for free

Note : The current page looks has been disoriented due to the
           new design to the blog . We will try to bring this back to
           normal as soon as possible . Sorry!!!

 While googling on the web for a  geocode address 
database which I needed for one of my projects and
after visitng a number of sites that did give   me
an geocode address database but at an cost ranging
from $30-$200 that I couldn't afford at any  cost.
So I decided to use Google Maps , Yahoo Maps   and  
Microsoft Bing Maps to  create  my  free   geocode
address database.So the first thing I had to check
out was which of this mapping giants would me give
me the most accurate results .So I started by 
testing out the values returned by each of the maps.
For well known places all 3 of them would give  me
accurate results, but as places became less famous,
Microsoft Bing really sucked & was giving me a city
level accuracy only!!!!

So Microsoft Bing Maps was ruled out as being suitable for creating 
 an geocode address database . Now the next option was Google Maps &  Yahoo
 Maps and the good news was that both were giving the most accurate & almost
 the same reuslts all the time .I wonder if this two Mapping Giants use the
 same common database ??  

Is there any difference between Google Maps and Yahoo Maps ???

Each has its own pros & cons and telling which one is better is still a tough job . 1)Google Maps is extensively used in many web applications as comapred to yahoo and graphic wise Google Maps is far more superior than Yahoo Maps . 2)Yahoo Maps takes less time to load than Google Maps . 3)Google Maps allows you to geocode address at 2000 queries per day . 4)Yahoo Maps on the other hand allows you to geocode address at the rate of 50,0000 queries a day i.e almost 25 times more queriies a day . 5)Google Maps Api allows you to use their Directions Api but Yahoo Maps Api doesn't allow you to use their Directions Api expect on the Yahoo Maps homepage .

So lets get started  setting up the geocode address database !! 

Yahoo Maps Geocode Address Database Creation

// Json encode the data
function json_code ($json) 
$json = substr($json, strpos($json,'{')+1, strlen($json));
$json = substr($json, 0, strrpos($json,'}'));
$json=preg_replace('/(^|,)([\\s\\t]*)([^:]*) (([\\s\\t]*)):(([\\s\\t]*))/s',
return json_decode('{'.$json.'}', true);

// function to get the geocode of the address
function geoCodeYp($point)
$yahoo_appid = 'Your yahoo app id'; // Replace your Yahoo AppID here            
$pointenc = urlencode($point);
// URL Formation that will fetch you the results on query
// get the contents of the URL formed
$jsondata = file_get_contents($url);
$json_data= '{
  a: 1,
  b: 245,
  c with whitespaces: "test me",
  d: "function () { echo \"test\" }",
  e: 5.66

 $coord=explode(" ",$point);
        // this will json encode the data .
        // line1 of addrress comprising of house,street no etc
        // line 2 of address comprising of city state country
 $line1 =$convertedtoarray['ResultSet']['Results']['0']['line1'] ;
 $line2 =$convertedtoarray['ResultSet']['Results']['0']['line1'] ;
 $county =$convertedtoarray['ResultSet']['Results']['0']['county'] ;
 $street =$convertedtoarray['ResultSet']['Results']['0']['street'] ;
$countrycode=$convertedtoarray['ResultSet']['Results']['0']['countrycode'] ;
$statecode  =$convertedtoarray['ResultSet']['Results']['0']['statecode']   ;
//$county   =$convertedtoarray['ResultSet']['Results']['0']['county'] ;
$city     =$convertedtoarray['ResultSet']['Results']['0']['city'] ; 
$house     =$convertedtoarray['ResultSet']['Results']['0']['house'] ;
$latitude   =$convertedtoarray['ResultSet']['Results']['0']['latitude'] ;
$longitude  =$convertedtoarray['ResultSet']['Results']['0']['longitude'] ;     

$yahooresults = array('countrycode'=>$countrycode,'statecode'=>$statecode,
 return $yahooresults ;

This are the two functions which you need to create the geocode address 
database . So how do I call this geocode function .
Include this two functions in a single  php  file .
1)Suppose you want to get the geocode address  of  a 
place say "Bohemia" . You can simply call the function as 
geoCodeYp("Bohemia") .
To further store the result in database :
$result=geoCodeYp("Bohemia") ;
// get each of the values as
.............remaining variables..................
You can store each of the results in database by retrieving
the remaining values .

2) To geocode address of a point(latitude&longitude)
// You have to include space between the latitude & longitude
$point=$latitude." ".$longitude ;
//call the geocode function

Time required to setup the geocode address database??

Suppose you have to want to geocode the address of around 5,00,000 address 1 yahoo appid -> 10 days 2 yahoo appid -> 5 days 10 yahoo appid -> 1 day
This way you can create your own geocode address database . 
"If you liked anything about this post or have any queries 
free feel to comment .
If you are not a developer & want help in setting up the 
geocode address database you can send me a mail or comment
on this post ."

Bookmark or Share this article :


Anonymous,  April 6, 2011 at 11:56 AM  

Thanks for the post , I have bookmarked this article .Just one question where do I get the yahoo app id?

Vaishakh Thayyil April 6, 2011 at 12:04 PM  

u can get the appid from

  © Blogger templates The Professional Template by 2008

Back to TOP