这是我的代码,用于动态获取特定经纬度的地址
来自数据库。如果我使用这个静态值,它工作得很好。但如果我用
$latlong 这个变量获取动态值。它显示错误。
有什么解决办法吗?请帮助我。
注意:第 21 行 C:\xampp\htdocs\demo_calLatLong\calLatLong.php 中未定义偏移量:0
注意:尝试在第 21 行获取 C:\xampp\htdocs\demo_calLatLong\calLatLong.php 中非对象的属性
<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
而不是直接访问文件。
Replace
<?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));
?>
To
<?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);
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)