繁体   English   中英

Google Maps API v3返回ZERO_RESULTS,但Maps.Google.com正常显示

[英]Google Maps API v3 returning ZERO_RESULTS but Maps.Google.com showing fine

需要一些帮助。

我正在使用Google Maps API v3来获取存储在数据库中的人类可读地址的经度和纬度,然后在Google Map画布上放置1个标记。 非常简单。

我遇到的问题是某些地址正在退回状态代码-> ZERO_RESULTS

如果我将相同的地址输入maps.google.com,他们将找到该特定区域并使用带有近似标记的标记对其进行映射。

我在数据库中拥有的某些地址不是特定的,这意味着它们可能没有邮政编码和/或可能没有城市,但都具有省/地区和国家/地区。 同样要注意的是,它们都没有街道地址。

一些人类可读的地址可能带有破折号(-),空格(),撇号(')和逗号(,)

返回零的地址的示例是:

Soul-t'ukpyolsi, Korea, South

在该特定示例中,“国家/地区”名称中包含逗号和空格,并且“地区”中也包含撇号和破折号。

这是我正在使用的Javascript代码:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=MYKEY&sensor=false"></script>
<script>
function initialize() {
  var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $long; ?>);
  var mapOptions = {
    zoom: 5,
    center: myLatlng
  }
  var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

  var marker = new google.maps.Marker({
      position: myLatlng,
      map: map
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

</script>

我正在使用PHP根据存储在数据库中的地址元素生成完整的地址路径。 这是我用来生成路径然后发出geolocator请求的代码:

请记住,城市和邮政编码/邮政编码是可选元素

// Replace any spaces in vars
if (isset($gmaps_city)){
    $gmaps_city = str_replace(" ","+",$gmaps_city);
}
if (isset($gmaps_province)){
    $gmaps_province = str_replace(" ","+",$gmaps_province);
}
if (isset($gmaps_country)){
    $gmaps_country = str_replace(" ","+",$gmaps_country);
}
if (isset($gmaps_pcode)){
    $gmaps_pcode = str_replace(" ","+",$gmaps_pcode);
}

// If Postal Code and City
if (isset($gmaps_city) AND isset($gmaps_pcode)){ 
    $gmaps_path = $gmaps_city.",+".$gmaps_province.",+".$gmaps_country.",+".$gmaps_pcode."&sensor=false"; 

// If City but no Postal Code
} else if (isset($gmaps_city) AND !isset($gmaps_pcode)){ 
    $gmaps_path = $gmaps_city.",+".$gmaps_province.",+".$gmaps_country."&sensor=false"; 

// If Postal Code but no City
} else if (!isset($gmaps_city) AND isset($gmaps_pcode)){ 
    $gmaps_path = $gmaps_province.",+".$gmaps_country.",+".$gmaps_pcode."&sensor=false"; 

// Only Province and Country
} else { 
    $gmaps_path = $gmaps_province.",+".$gmaps_country."&sensor=false"; 
}

// Determine Lat and Long of Address
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$gmaps_path);

$output= json_decode($geocode);

$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;

$status = $output->status;

任何帮助是极大的赞赏。

该示例可能由于拼写错误而引起问题。 以下内容:“韩国南朝鲜的首尔-t'ukpyolsi”不返回ZERO_RESULTS。

破折号和撇号不应导致基于您的代码的问题。 请提供另一个示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM