Created
June 26, 2014 14:15
-
-
Save mrded/e051b21b1a18d231eaef to your computer and use it in GitHub Desktop.
Drupal 7: Get location object by address string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get location object by address string. | |
* | |
* @param string $location | |
* | |
* @return array | |
* | |
* @dependencies geocoder module. | |
*/ | |
function wj_users_fboauth_get_location($location = '') { | |
$point = geocoder('google', $location); | |
$output = array(); | |
foreach ($point->data['geocoder_address_components'] as $component) { | |
if ($component->types[0] == 'locality') { | |
$output['city'] = array( | |
'name' => $component->long_name, | |
); | |
continue; | |
} | |
if ($component->types[0] == 'country') { | |
$output['country'] = array( | |
'name' => $component->long_name, | |
'iso2' => $component->short_name, | |
); | |
continue; | |
} | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment