Advertisement
FIZIXAgency

GeoNames PHP API to Resolve Location

Jul 12th, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. /* Resolve city from long/lat data using GeoNames API. Example uses the demo account, a live site would need an API key. */
  2. public function resolveCity($lat, $lng)
  3. {
  4.    $url = "http://api.geonames.org/findNearbyPlaceNameJSON?lat=" . $lat . "&lng=" . $lng . "&username=demo";
  5.    
  6.    // make the HTTP request
  7.    $data = @file_get_contents($url);
  8.    
  9.    $jsondata = json_decode($data,true);
  10.    
  11.    
  12.    // Grab the location
  13.    $location = $jsondata['geonames'][0]['name'];
  14.    
  15.    
  16.    // Return the location
  17.    return $location;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement