duanlijia5864 2016-08-12 09:32
浏览 113
已采纳

Google Maps API距离矩阵请求

I've been using the Google Distance Matrix API for a while now to calculate distances between the consumer and businesses on my website; I have currently hit a wall and seen that my quote hits 2,500 and doesn't process anymore requests after that.

I then decided to give the documentation a quick read over to see if there's anything I could do to maybe kill two birds with one stone, so to say, and seen on the API Usage Limits Page that you have have 25 origins and 25 destinations per requests.

Does this means that within one request I can concatenate 25 origins and destinations and return their miles.

Here's the PHP code I use to get the milage between the consumer and customer:

final public function Distance($A, $B){

    $URL = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=".urlencode($A)."&destinations=".urlencode($B)."&key=API_KEY_HERE";
    $Data = json_decode(file_get_contents($URL));

    return str_replace(" mi", "", $Data->rows->elements->distance->text);        
}
  • 写回答

2条回答 默认 最新

  • duandong7980 2016-08-12 09:37
    关注

    The quota is in terms of elements:

    Users of the standard API:

    2,500 free elements per day, calculated as the sum of client-side and server-side queries.

    Also:

    Each query sent to the Google Maps Distance Matrix API is limited by the number of allowed elements, where the number of origins times the number of destinations defines the number of elements.

    Adding more origins/destinations to a request won't increase the amount of distances that can be retrieved before hitting the quota.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?