Created
August 27, 2013 19:39
-
-
Save nclsjstnn/6358050 to your computer and use it in GitHub Desktop.
[PHP] Get the administrative number of a region from a Chilean address
This file contains 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
//kinda oldschool but it could help you in some project in Chile | |
$address = urlencode(utf8_encode($_GET['address'])); | |
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='. $address .'®ion=cl&sensor=false'); | |
$output= json_decode($geocode); | |
for ( $i = 0; $i < count ( $output->results[0]->address_components ); $i ++ ) { | |
switch ( $output->results[0]->address_components[$i]->types[0] ) { | |
case "administrative_area_level_1": | |
$region = $output->results[0]->address_components[$i]->long_name; | |
break; | |
} | |
} | |
$latitude = $output->results[0]->geometry->location->lat; | |
$longitude = $output->results[0]->geometry->location->lng; | |
if ($region == 'Tarapacá') { $region_id = '1'; } | |
elseif ($region == 'Atacama') { $region_id = '3'; } | |
elseif ($region == 'Coquimbo') { $region_id = '4'; } | |
elseif ($region == 'Santiago Metropolitan Region') { $region_id = '13'; } | |
elseif ($region == 'Los Lagos') { $region_id = '10'; } | |
elseif ($region == 'Valparaíso') { $region_id = '5'; } | |
elseif ($region == 'Antofagasta') { $region_id = '2'; } | |
elseif ($region == "O'Higgins Region") { $region_id = '6'; } | |
elseif ($region == 'Maule') { $region_id = '7'; } | |
elseif ($region == 'Bío-Bío') { $region_id = '8'; } | |
elseif ($region == 'Araucanía') { $region_id = '9'; } | |
elseif ($region == 'Aysén Region') { $region_id = '11'; } | |
elseif ($region == 'Magallanes and Antártica Chilena Region') { $region_id = '12'; } | |
elseif ($region == 'Los Ríos Region') { $region_id = '14'; } | |
elseif ($region == 'Arica and Parinacota Region') { $region_id = '15'; } | |
print(The administrative number from ".$address." (lat:".$latitude.", lng:".$longitude.") it's: ".$region_id." ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment