Google Places API error
-
04-12-2019 - |
题
I'm trying to request all places in central London within a radius of 1000 meters using Google Places API, the required output type is XML.
This is my code using 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>
Unfortunately, I only receive the error
message. The Firebug console shows me XML Parsing Error: no element found Location: moz-nullprincipal:{7577ff8b-21cb-40c5-824b-de812540f29e} Line Number 1, Column 1:
.
I have obtained my own API key and turned the Places API
on. (The website URL is "http://localhost/", since I'm coding local using XAMPP.)
解决方案
You cannot request ressources from different domains using AJAX, it's restricted by same-origin-policy.
Use the maps-API to get the results.
不隶属于 StackOverflow