Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Now supports reverse geocoding

  • Loading branch information...
commit 77b1e77cd56fdadd754f75d61ed10d746bb5993d 1 parent 80f73b3
@ollierattue authored
Showing with 53 additions and 9 deletions.
  1. +53 −9 libraries/yahoo_placefinder.php
View
62 libraries/yahoo_placefinder.php
@@ -36,7 +36,7 @@ public function __construct()
$this->yahoo_geo_app_id = $this->CI->config->item('yahoo_geo_app_id');
- log_message('debug', "Yahoo Placefiner Class Initialized");
+ log_message('debug', "Yahoo Placefinder Class Initialized");
}
// --------------------------------------------------------------------
@@ -44,22 +44,68 @@ public function __construct()
/**
* Geocode - supports http://developer.yahoo.com/geo/placefinder
* @access public
- * @param string - refers to postal in database
+ * @param string
* @return array or FALSE
*/
- function geocode($postal_code = NULL)
+ function geocode($location = NULL)
{
- // Open the cURL session
- $curlSession = curl_init();
- $postal_code = urlencode($postal_code);
+ $location = urlencode($location);
if (!$this->yahoo_geo_app_id)
{
return FALSE;
}
- $url = "http://where.yahooapis.com/geocode?postal={$postal_code}&flags=P&appid={$this->yahoo_geo_app_id}";
+ $url = "http://where.yahooapis.com/geocode?location={$location}&flags=P&appid={$this->yahoo_geo_app_id}";
+
+ $geo_data = $this->do_curl($url);
+
+ $geo_data['longitude'] = $geo_data['ResultSet']['Result'][0]['longitude'];
+ $geo_data['latitude'] = $geo_data['ResultSet']['Result'][0]['latitude'];
+
+ return $geo_data;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Geocode - supports http://developer.yahoo.com/geo/placefinder
+ * @access public
+ * @param string
+ * @param string
+ * @return array or FALSE
+ */
+
+ function reverse_geocode($lat = NULL, $lng = NULL)
+ {
+ $latlng = urlencode($lat.', '.$lng);
+
+ if (!$this->yahoo_geo_app_id)
+ {
+ return FALSE;
+ }
+
+ $url = "http://where.yahooapis.com/geocode?location={$latlng}&flags=P&gflags=R&appid={$this->yahoo_geo_app_id}";
+
+ $geo_data = $this->do_curl($url);
+
+ return $geo_data;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Geocode - supports http://developer.yahoo.com/geo/placefinder
+ * @access public
+ * @param string - refers to postal in database
+ * @return array or FALSE
+ */
+
+ private function do_curl($url)
+ {
+ // Open the cURL session
+ $curlSession = curl_init();
// Set the URL
curl_setopt ($curlSession, CURLOPT_URL, $url);
@@ -90,8 +136,6 @@ function geocode($postal_code = NULL)
$geo_data = unserialize($rawresponse);
// Convenience array names
- $geo_data['longitude'] = $geo_data['ResultSet']['Result'][0]['longitude'];
- $geo_data['latitude'] = $geo_data['ResultSet']['Result'][0]['latitude'];
return $geo_data;
}
Please sign in to comment.
Something went wrong with that request. Please try again.