Google Places API错误
问题描述:
我试图请求使用Google Places API在伦敦市中心半径1000米内的所有地方,所需的输出类型是XML。
这是使用JQuery我的代码:Google Places API错误
<!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
消息。萤火虫控制台显示我XML Parsing Error: no element found Location: moz-nullprincipal:{7577ff8b-21cb-40c5-824b-de812540f29e} Line Number 1, Column 1:
。
我已经获得了我自己的API密钥,并打开了Places API
。 (网址是“http:// localhost /”,因为我使用XAMPP编码本地。)
答
您不能使用AJAX请求来自不同域的资源,它受同源策略限制。
使用maps-API获取结果。
我的意思是javascript-API:http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/places.html – 2012-03-03 21:14:10
非常感谢! – 2012-03-03 21:15:03