简体   繁体   English

对Google Maps API的AJAX请求停止工作

[英]AJAX request to Google Maps API stopped working

I am trying to use Google Maps API in my application. 我正在尝试在应用程序中使用Google Maps API。 I am not able to get result out of this simple API request. 我无法从这个简单的API请求中得到结果。 A week ago this code was working perfectly. 一周前,这段代码运行良好。 I don't know if there is a problem in the Google's service or my code. 我不知道Google的服务或我的代码是否有问题。

Here is my request: 这是我的要求:

       $.ajax({
            type: "GET",
            url: apilink,
            data: {
                origin: start.replace(/ /g, '+'),
                destination: end.replace(/ /g, '+'),
                waypoints: 'optimize:true|' + waypts.join('|').replace(/ /g, '+'),
                travelMode: google.maps.DirectionsTravelMode.DRIVING,
                sensor: false
            },
            dataType: "json"
        }).done(function (response) {
        alert("inside done");
       });

Looking into my javascript console, this was my request : 查看我的JavaScript控制台,这是我的请求:

https://maps.googleapis.com/maps/api/directions/json?&origin=Chennai,+Tamil+Nadu,+India&destination=New+Delhi,+Delhi,+India&waypoints=optimize:false|New+Delhi,+Delhi,+India&travelMode=DRIVING&sensor=false https://maps.googleapis.com/maps/api/directions/json?&origin=Chennai,+Tamil+Nadu,+India&destination=New+Delhi,+Delhi,+India&waypoints=optimize:false|New+Delhi,+Delhi ,+印度&travelMode = DRIVING&传感器=假

Now as I open this link, I am able to see the JSON response. 现在,当我打开此链接时,我可以看到JSON响应。 But I am not able to get the alert "inside done". 但是我无法“在内部完成”警报。

What has gone wrong in just few days ? 短短几天出了什么问题?

done() is equivalent to the old success() call - this gets called only when the call succeeds. done()等效于旧的success()调用-仅在调用成功时才调用。 If the call fails, done callbacks will not be excuted. 如果调用失败,将不会执行已完成的回调。 Always add a fail callback to ajax calls. 始终向ajax调用添加失败回调。 If for nothing else, then just to remind yourself that this call can fail someday and the business rules don't yet specify what has to be done in that case. 如果没有别的,则只是提醒自己,该呼叫有一天可能会失败,并且业务规则尚未指定在这种情况下必须执行的操作。

As for your particular case, you may have hit your daily limit. 至于您的特殊情况,您可能已达到每日限额。 It has happened to me before. 以前发生在我身上。 Google's restrictions on the free usage are very generous when it comes to personal uses but are crippling if you are just scraping driving directions :) Google对于免费使用的限制非常宽泛,涉及个人用途,但如果您只是在刮擦行车路线的话,它就会变得残酷:)

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

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