<?php
function lookup($string){
$string = str_replace (" ", "+", urlencode($string));
$details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
// print_r($response);
echo "<h2>curl response</h2>".show_var($response);
// If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
if ($response['status'] != 'OK') { return null; }
$geometry = $response['results'][0]['geometry']['location'];
$array = array(
'formatted_address' => $response['results'][0]['formatted_address'],
'address_type' => $response['results'][0]['types'][0],
'latitude' => $geometry['lat'],
'longitude' => $geometry['lng'],
);
return $array;
}
require_once 'myUtils/show_vars.php';
$city = '2 Via Monastero Calascibetta';
$array = lookup($city);
// print_r($array);
echo "<h2>received values</h2>".show_var($array);
?>