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!!!
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 ?? | |
| |
| |
// 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', '$1"$3"$4:',trim($json)); 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 $url="http://where.yahooapis.com/geocode? location=".$pointenc."&gflags=R&appid=".$yahoo_appid."&flags=J";
// 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 . $convertedtoarray=$this->json_code($jsondata); // 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'] ;
if(($line1=="")||($line2=="")||($county=="")||($street==""))
{
$yahooresults['status']="noresult";
}
else
{
$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, 'county'=>$county,'city'=>$city,'street'=>$street,'house'=>$house, 'latitude'=>$latitude,'longitude'=>$longitude); }
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
| |
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 : |
2 comments:
Thanks for the post , I have bookmarked this article .Just one question where do I get the yahoo app id?
u can get the appid from
https://developer.apps.yahoo.com/wsregapp/
Post a Comment