1

我正在尝试使用Google Places API请求伦敦市中心半径 1000 米内的所有地点,所需的输出类型是 XML。
这是我使用 JQuery 的代码:

<!DOCTYPE html>
<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    </head>
    <body>
        <script>              
            jQuery(document).ready(function(){             
                jQuery.ajax({
                    url: 'https://maps.googleapis.com/maps/api/place/search/xml',
                    dataType: 'xml',
                    type: 'GET',
                    data:  {
                        key: 'MY KEY', 
                        location: '51.526688,-0.123825',
                        radius: 1000,
                        sensor: 'false',
                        types: 'food'
                    },
                    success: function(data){
                        alert("success");
                    },
                    error: function(data){
                        alert("error");
                    }
                });
            });
        </script>
    </body>
</html>

不幸的是,我只收到error消息。Firebug 控制台向我展示了XML Parsing Error: no element found Location: moz-nullprincipal:{7577ff8b-21cb-40c5-824b-de812540f29e} Line Number 1, Column 1:.

我已经获得了自己的 API 密钥并打开了Places API。(网站 URL 是“http://localhost/”,因为我使用 XAMPP 进行本地编码。)

4

1 回答 1

2

您不能使用 AJAX 从不同的域请求资源,它受到同源策略的限制。

使用 maps-API 获取结果。

于 2012-03-03T20:35:29.370 回答