如何使用 json api 将 Lat Long 转换为 php 中的地址?
How to convert Lat Long to address in php with json api?
This is my code to get address off particular lat long dynamically
from db.If i used this static value it works fine. but if i used
$latlong this variable to get dynamic values. it shows error.
what's the solution for this. please help me with the same.
注意:第 21 行 C:\xampp\htdocs\demo_calLatLong\calLatLong.php 中未定义的偏移量:0
注意:试图在 C:\xampp\htdocs\demo_calLatLong\calLatLong.php 的第 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
直接访问文件。
替换
<?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);
?>
This is my code to get address off particular lat long dynamically from db.If i used this static value it works fine. but if i used $latlong this variable to get dynamic values. it shows error. what's the solution for this. please help me with the same.
注意:第 21 行 C:\xampp\htdocs\demo_calLatLong\calLatLong.php 中未定义的偏移量:0 注意:试图在 C:\xampp\htdocs\demo_calLatLong\calLatLong.php 的第 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
直接访问文件。
替换
<?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);
?>