1

我有这段代码试图从印地语中获取演示数据,例如,我从我在桌面中创建的本地 .html 运行它。

var xmlhttp;

if (window.XMLHttpRequest)
{
    xmlhttp = new XMLHttpRequest();
}
else
{
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.open("GET", "http://maps.googleapis.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&language=hi&sensor=true", true);

xmlhttp.onreadystatechange = function ()
{
    if (xmlhttp.readyState != 4) return;
    if (xmlhttp.status != 200 && xmlhttp.status != 304) return;
    document.write(xmlhttp.responseText);
};

xmlhttp.send(null);

谷歌不允许我获取数据,因为Access-Control-Allow-Origin. 我该怎么做才能得到这些数据,我真的很困惑......

4

1 回答 1

1

您应该使用带有内置地理编码服务的 JavaScript Google Maps API,而不是使用直接的网络调用。您可以将语言设置为 JavaScript 加载器的参数:maps.googleapis.com/maps/api/js?sensor=false&language=hi

于 2012-10-18T23:28:17.050 回答