function location_geocode_au_google in Location 5.3
File
- supported/
location.au.inc, line 288
Code
function location_geocode_au_google($location = array()) {
$service_url = 'http://maps.google.com/maps/geo?output=xml&key=' . variable_get('location_geocode_au_google_apikey', '') . '&q=';
$address = location_address2singleline($location);
$http_reply = drupal_http_request($service_url . urlencode($address));
$status_code_match = array();
preg_match('/<code>(.*)<\\/code>/', $http_reply->data, $status_code_match);
$status_code = $status_code_match[1];
if ($status_code != 200) {
watchdog('location', t('Google geocoding returned status code: %status_code', array(
'%status_code' => $status_code,
)));
return NULL;
}
$accuracy_code_match = array();
preg_match('/Accuracy="([0-9])"/', $http_reply->data, $accuracy_code_match);
$accuracy_code = $accuracy_code_match[1];
$min_accuracy = variable_get('location_geocode_au_google_accuracy_code', variable_get('location_geocode_google_minimum_accuracy', '3'));
if ($accuracy_code < $min_accuracy) {
watchdog('location', t('Google geocoding result for %country did not meet the minimum accuracy level of %min_accuracy. Result accuracy: %accuracy_code', array(
'%country' => $location['country'],
'%min_accuracy' => $min_accuracy,
'%accuracy_code' => $accuracy_code,
)));
return NULL;
}
$latlon_match = array();
preg_match('/<coordinates>(.*)<\\/coordinates>/', $http_reply->data, $latlon_match);
$latlon_exploded = explode(',', $latlon_match[1]);
return array(
'lat' => $latlon_exploded[1],
'lon' => $latlon_exploded[0],
);
}