Friday, January 13

get longitude and latitude from an address with PHP and Google Maps API :Example

<?php
$url = "http://maps.google.com/maps/api/geocode/json?address=india+gujrat+rajkot&sensor=false&region=India";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response);
echo "<pre>";
print_r($response);
echo "<pre>";

echo "Latitude : ".$lat = $response->results[0]->geometry->location->lat;
echo "<br/>";
echo "Longitude :".$long = $response->results[0]->geometry->location->lng; 
?>

Example 2:

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://completion.amazon.com/search/complete?search-alias=aps&client=amazon-search-ui&mkt=1&q=google");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
echo curl_getinfo($curl, CURLINFO_HTTP_CODE); // code here
curl_close($curl);

die();
echo "<pre>";
print_r(json_decode($result));//return amazone autocomplete suggestion
echo "</pre>";
?>

No comments:

Post a Comment

10 Best Chatting Apps In India

  The modern world is all about Internet. There was a time when people use to pay high telephone bills to stay in touch with their friends a...