function google_geocode_location in Location 6.3
Same name and namespace in other branches
- 5.3 geocoding/google.inc \google_geocode_location()
- 5 geocoding/google.inc \google_geocode_location()
- 7.5 geocoding/google.inc \google_geocode_location()
- 7.3 geocoding/google.inc \google_geocode_location()
- 7.4 geocoding/google.inc \google_geocode_location()
Perform a geocode on a location array.
Parameters
$location: The location array to process.
Return value
an associative array with keys 'lat' and 'lon' containing the coordinates.
File
- geocoding/
google.inc, line 38 - Google geocoder.
Code
function google_geocode_location($location = array()) {
$query = array(
'region' => $location['country'],
'address' => _google_geocode_flatten($location),
'sensor' => 'false',
);
$url = url('http://maps.googleapis.com/maps/api/geocode/json', array(
'query' => $query,
'external' => TRUE,
));
$http_reply = drupal_http_request($url);
$data = json_decode($http_reply->data);
if ($data->status != 'OK') {
watchdog('location', 'Google geocoding returned status code: %status_code for the query url: %url', array(
'%status_code' => $data->status,
'%url' => $url,
));
return NULL;
}
$location = $data->results[0]->geometry->location;
return array(
'lat' => $location->lat,
'lon' => $location->lng,
);
}