0

我正在尝试使用 PHP 中的 mapmyindia geocode api 获取给定地址的经纬度。
它给出了一个错误:

试图在第 26 行的 C:\xampp\htdocs\api2.php 中获取非对象的属性

<!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;

?>
4

0 回答 0