-1

当我尝试向 Google 地方信息添加地点时,出现错误:

{"readyState":0,"responseText":"","status":0,"statusText":"error"}

这是我的代码:

HTML:

<form id="addShopForm">

          ...

        <a type="submit" id="submitshop">Submit</a>

</form>

查询:

 $('#submitshop').click(function(){
 $.ajax({
                    type: "POST",
                    url: "https://maps.googleapis.com/maps/api/place/add/json?sensor=true&key=asdEFasdBaasdasdasdMrN2ST5tRS5c",
                    crossDomain: true,
                    data: {
                       "location": {
                        "lat": 68.7425471,
                        "lng": 9.1370879
                       },
                       "accuracy": 50,
                       "name": "Test Shop!",
                       "language": "de"
                    },
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        alert(JSON.stringify(msg));
                    },
                    error: function (errormessage) {
                        alert(JSON.stringify(errormessage));
                        //{"readyState":0,"responseText":"","status":0,"statusText":"error"}
                    }
                });
});
4

1 回答 1

0

我也一直在努力让它发挥作用。执行您的代码后,我在我的 chrome 调试器中发现了这个错误:

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key={Key}
Failed to load resource: Origin http://localhost:8888 is not allowed by Access-Control Allow-Origin. 
https://maps.googleapis.com/maps/api/place/add/json?sensor=false&{key}
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key={Key}. 
Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin. 

因此,即使您在 ajax 对象中指定了它,google maps places API 似乎也不支持跨域。

幸运的是,有一个客户端 javascript 库。不幸的是,它不支持添加地点或事件:(。

我希望 google 将来能增加对 places API 的支持。

于 2013-09-19T15:06:25.030 回答