function location_geocode_us_yahoo in Location 5
Same name and namespace in other branches
- 5.3 supported/location.us.inc \location_geocode_us_yahoo()
- 6.3 supported/location.us.inc \location_geocode_us_yahoo()
- 7.5 supported/location.us.inc \location_geocode_us_yahoo()
- 7.3 supported/location.us.inc \location_geocode_us_yahoo()
- 7.4 supported/location.us.inc \location_geocode_us_yahoo()
File
- supported/
location.us.inc, line 245
Code
function location_geocode_us_yahoo($location = array()) {
$service_url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=" . variable_get('location_geocode_us_yahoo_appid', "YahooDemo") . "&location=";
$address = location_address2singleline($location);
$http_reply = drupal_http_request($service_url . urlencode($address));
// address may have been improperly formatted or invalid
if ($http_reply->code == 400) {
return NULL;
}
else {
// got a successful reply, but we only want to return if we have address-level precision
$matches = array();
preg_match('/precision="([a-z]*)"/', $http_reply->data, $matches);
if ($matches[1] != 'address') {
// The precision we got back was not down to the street-address level
return NULL;
}
else {
$lat_match = array();
$lon_match = array();
$latlon = array();
if (preg_match('/<Latitude>(.*)<\\/Latitude>/', $http_reply->data, $lat_match)) {
$latlon['lat'] = $lat_match[1];
}
else {
return NULL;
}
if (preg_match('/<Longitude>(.*)<\\/Longitude>/', $http_reply->data, $lon_match)) {
$latlon['lon'] = $lon_match[1];
return $latlon;
}
else {
return NULL;
}
}
}
}