我可以使用 XmlHttpRequest 调用批量地理编码器请求吗?

Can I call batch geocoder request with XmlHttpRequest?

我正在尝试使用 XmlHttpRequest 对 here.com API 进行批量地理编码调用,但没有得到任何结果

根据 HERE.COM 文档,我可以对

进行批量地理编码调用
https://batch.geocoder.api.here.com/6.2/jobs?app_id={YOUR_APP_ID}&pp_code={YOUR_APP_CODE}&mailto=<your_email_address>&outdelim=|&outcols=displayLatitude,displayLongitude,locationLabel,  houseNumber,street,district,city,postalCode,county,state,country&outputcombined=false

然后,在 POST 正文中

recId|searchText|country
0001|Invalidenstraße 116 10115 Berlin|DEU
0002|Am Kronberger Hang 8 65824 Schwalbach|DEU
0003|425 W Randolph St Chicago IL 60606|USA

我正在尝试使用来自 JavaScript 的 XmlHttpRequest 获得一些响应,使用此代码:

geocode = function()    {
    var xhttp = new XMLHttpRequest();

    var osmURL="https://batch.geocoder.api.here.com/6.2/jobs"
        +"?app_id=0aApOideNwpiPyzejpFk"
        +"&app_code=Hz7Rz_PodmUhdG8KCDSgk_g"
        +"&mailto=joan.the.best@gmail.com"
        +"&outdelim=|"
        +"&outcols=recId,displayLatitude,displayLongitude"
        +"&outputcombined=false"        
        +"&language=de-DE"

    xhttp.onreadystatechange = function() {
        alert(xhttp.responseText);
        if (this.readyState == 4 && this.status == 200) {
            alert(xhttp.responseText);
        }
    };

    xhttp.onload = function() {
        alert(xhttp.responseText);
        alert(this.status);
        if (this.readyState == 4 && this.status == 200) {
            alert(xhttp.responseText);
        }
    };

    var postToSend = 
        "recId|searchText|country" + "\r\n" +
        "0001|Invalidenstraße 116 10115 Berlin|DEU" + "\r\n" + 
        "0002|Am Kronberger Hang 8 65824 Schwalbach|DEU" + "\r\n" +
        "0003|425 W Randolph St Chicago IL 60606|USA";

    xhttp.open("POST", osmURL, true);
    xhttp.send(postToSend);
}

我希望输出类似于:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
  <Response>
    <MetaInfo>
      <RequestId>qr9jVjuoFe1mULUvBlXr7UK4dM8BpAkO</RequestId>
    </MetaInfo>
    <Status>submitted</Status>
    <TotalCount>0</TotalCount>
    <ValidCount>0</ValidCount>
    <InvalidCount>0</InvalidCount>
    <ProcessedCount>0</ProcessedCount>
    <PendingCount>0</PendingCount>
    <SuccessCount>0</SuccessCount>
    <ErrorCount>0</ErrorCount>
    </Response>
</ns2:SearchBatch>

但是没有返回结果,甚至没有状态。我已经毫无问题地完成了个别呼叫,因此 URL 必须可以接通。

你试过这样的东西吗?

提前致谢, 琼.

编辑:进一步调查,我收到一个 "XMLHttpRequest: Network Error 0x80070005, Access is denied" 错误,以及一些与 CORS 相关的错误。我如何出示有效凭据以允许访问?谢谢

也许 'outdelim' 参数的编码是罪魁祸首;改变管道'|'到“%7C”。这也适用于 'indelim'.

另见 The Batch Geocoder API returns only failed status