Google maps 为什么谷歌地理编码api发送奇怪的结果?
当我在谷歌地图中输入地址'81 w哥伦布街,俄亥俄州利托波利斯,43136时,它会确认地址,发回坐标,并在地图上显示一个标记。然而,当我在脚本中使用相同的地址时,我会得到完全不同的JSON地址/响应。 如果需要,可以使用一些代码: 表格:Google maps 为什么谷歌地理编码api发送奇怪的结果?,google-maps,google-geocoding-api,Google Maps,Google Geocoding Api,当我在谷歌地图中输入地址'81 w哥伦布街,俄亥俄州利托波利斯,43136时,它会确认地址,发回坐标,并在地图上显示一个标记。然而,当我在脚本中使用相同的地址时,我会得到完全不同的JSON地址/响应。 如果需要,可以使用一些代码: 表格: <form action="json-decode-script.php" name="my-form" id="my-form" method="post"> <input name="street_add"
<form action="json-decode-script.php" name="my-form" id="my-form" method="post">
<input name="street_add" id="street_add" type="textbox" placeholder="street addres" class="address">
<input name="city" id="city" type="textbox" placeholder="city" class="address">
<input name="state" id="state" type="textbox" placeholder="state" class="address">
<input name="postcode" id="postcode" type="textbox" placeholder="zipcode" class="address">
<input type="submit" id="submit" value="go">
</form>
剧本:
<?php
$street_add = (isset($_POST['street_add'])) ? $_POST['street_add'] : '';
$city = (isset($_POST['city'])) ? $_POST['street_add'] : '';
$state = (isset($_POST['state'])) ? $_POST['street_add'] : '';
$postcode = (isset($_POST['postcode'])) ? $_POST['postcode'] : '';
$address = $street_add . ',' . $city . ',' . $state . ',' . $postcode;
$latitude = '';
$longitude = '';
// Send Encoded address to google api
$json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.rawurlencode($address).'&sensor=false');
// Convert json to array
$array = json_decode($json);
// Results
$formatted = $array->results[0]->formatted_address;
$latitude = $array->results[0]->geometry->location->lat;
$longitude = $array->results[0]->geometry->location->lng;
$theStreetNum = $array->results[0]->address_components[0]->long_name;
$theStreetName = $array->results[0]->address_components[1]->long_name;
$street_add = $theStreetNum . ' ' . $theStreetName;
$theCity = $array->results[0]->address_components[3]->long_name;
$theState = $array->results[0]->address_components[6]->short_name;
$thePostCode = $array->results[0]->address_components[8]->long_name;
?><pre><?php
print_r($array);
?></pre>
还要注意的是,我使用的其他地址工作正常。,看起来您正在使用Web服务。您用于请求的URL是什么。响应是什么样子的?URL在上面的代码中;)结果看起来像一个格式良好的stdClass;)(地址不正确)。另外,Javascript API对我也适用!这就是为什么这是如此奇怪!我看到的其他一些回复表明,不同的API在某种程度上对结果的处理方式不同,因此…..代码的最终结果URL是什么?My似乎工作正常。虽然,它应该是@(尽管我怀疑这会改变任何事情)