我对谷歌 API 网址有疑问。我想从邮政编码中获取地址。但我无法获得价值
我的代码是
<script type="text/javascript">
var filter_new = "60609";
var request = new XMLHttpRequest();
request.open("GET", "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address="+filter_new, false);
request.send();
var xml = request.responseXML;
var users = xml.getElementsByTagName("GeocodeResponse");
for(var i = 0; i < users.length; i++)
{
var user = users[i];
var names = user.getElementsByTagName("formatted_address");
for(var j = 0; j < names.length; j++)
{
var filter_new1=names[j].childNodes[0].nodeValue;
}
}
alert(filter_new1);
</script>
当我运行此代码时,它显示以下错误:
XMLHttpRequest cannot load http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=60609. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101
请帮我。