28 marzo, 2017
Obtener latitud y longitud a partir de una dirección con PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php $direccion = 'Calle Serrano 154, Madrid, España'; // Obtener los resultados JSON de la peticion. $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($direccion).'&sensor=false'); // Convertir el JSON en array. $geo = json_decode($geo, true); // Si todo esta bien if ($geo['status'] = 'OK') { // Obtener los valores $latitud = $geo['results'][0]['geometry']['location']['lat']; $longitud = $geo['results'][0]['geometry']['location']['lng']; } echo "Latitud: ".$latitud." longitud: ".$longitud; |
Fuente: http://www.alvarolara.com/2017/03/22/obtener-latitud-y-longitud-a-partir-de-una-direccion-con-php/
Read More