本文介绍了如何使用json api将Lat Long转换为php中的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
注意:未定义的偏移量:第21行的C:\ xampp \ htdocs \ demo_calLatLong \ calLatLong.php中的0注意:尝试在第21行的C:\ xampp \ htdocs \ demo_calLatLong \ calLatLong.php中获取非对象的属性
Notice: Undefined offset: 0 in C:\xampp\htdocs\demo_calLatLong\calLatLong.php on line 21Notice: Trying to get property of non-object in C:\xampp\htdocs\demo_calLatLong\calLatLong.php on line 21
<table class="table table-bordered">
<thead>
<tr>
<th>Client Name</th>
</tr>
</thead>
<?php
include 'db.php';
$sql = 'SELECT * FROM `location`';
$travel = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_array($travel))
{?>
<tbody>
<tr class="active">
<?php
$latlong = $row[1].','.$row[2];
$geocode=json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=19.0978,22.8972&sensor=false',true));
?>
<td><?php echo $geocode->results[0]->formatted_address;?></td>
</tr>
</tbody>
<?php }?>
</table>
推荐答案
您尝试访问的不是文件的url,而是使用CURL
直接访问文件.
You are trying to access url not a file, Use CURL
instead to access file direct.
替换
<?php
$latlong = $row[1].','.$row[2];
$geocode=json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=19.0978,22.8972&sensor=false',true));
?>
收件人
<?php
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$row[1],$row[2]&sensor=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$geocode = json_decode($output);
?>
这篇关于如何使用json api将Lat Long转换为php中的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!