简体   繁体   English

在google API中根据经纬度计算地址(一个请求中计算多个地址)

[英]Calculate address from latitude and longitude in google API (More than one address calculation in one request)

This function for Reveres Geocoding works well for me. Reveres Geocoding 的这个功能对我来说效果很好。 I have to display the address in the information window of a marker, and there are more then 200 in one map.我必须在标记的信息窗口中显示地址,而一张地图中有200多个。 I built the code below and it works perfectly.我构建了下面的代码,它运行完美。 However, Google's API request limit of 2500/day gets exceeded easily.但是,Google 的 API 请求限制 2500/天很容易被超过。 Is there any way in I can bulk request Google's API?有什么方法可以bulk request Google 的 API?

Our project is currently a small one, so buying more requests/day isn't an option for us.我们的项目目前是一个小项目,因此每天购买更多请求不是我们的选择。

<?php 
function getaddress($lat,$lng)
{
  $url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($lng).'&sensor=false';
  $json = @file_get_contents($url);
  $data=json_decode($json);
  $status = $data->status;
  if($status=="OK")
  return $data->results[0]->formatted_address;
  else
  return false;
}
?>

No, you can't "bulk query" a bunch of addresses and have it only count as one request when using the standard API .不,您不能“批量查询”一堆地址,并且在使用标准 API时只能将其计为一个请求。 Each lookup counts as a request.每次查找都算作一次请求。

There are other APIs that don't have limits, or allow more lookups, like MapQuest. 还有其他没有限制或允许更多查找的API ,例如 MapQuest。 If you're hitting the daily limit with Google, try using another API.如果您使用 Google 达到每日限制,请尝试使用其他 API。

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

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