我有一个带有坐标(纬度,经度)的数组......这个数组有大约 60-80 个项目......
在我的 foreach 循环中有...
...{
$lat = substr($xx[1],0,8);
$long = substr($xx[0],0,8);
?>
<script type="text/javascript">
// <![CDATA[
$(function() {
var geocoder = new google.maps.Geocoder();
function geocodePosition(pos,pos2) {
geocoder.geocode({
latLng: new google.maps.LatLng(pos,pos2)
}, function(responses) {
if (responses && responses.length > 0) {
console.log(responses[0].formatted_address);
} else {
console.log('Cannot determine address at this location.');
}
});
}
geocodePosition(<?php echo $lat ?>,<?php echo $long ?>);
});
// ]]>
</script>
<?php } ...
地理编码器最多可在 5 个坐标处进行地理编码,其他则带有输出“无法确定此位置的地址”。
当我采用其中一些“无法确定”时,我手动使用它们(仅 1 项 = 纬度和经度,而不是整个数组)它可以工作。
那么问题出在哪里?