0

I'm trying to get lat and long of a given address using mapmyindia geocode api in Php.
It's giving an error :

Trying to get property of non-object in C:\xampp\htdocs\api2.php on line 26

<!DOCTYPE html>
<html>
<form method="post">
<input type="text" name="address">
<input type="submit" name="submit" value="submit">
</form>
</html>
<?php

//Formatted address
$address = "vijay nagar,indore";
//Send request and receive json data by address
$url = "https://api.mapmyindia.com/v3?fun=geocode&lic_key = mykey &address=$address";

$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);

$output = json_decode($response);

echo $lat = $output->results[0]->geometry->location->lat;
echo "<br />";
echo $long = $output->results[0]->geometry->location->lng;

?>

0 Answers0