微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

这里映射用于批量反向地理编码位置的 API 每次都在已完成的作业上返回 SuccessCount 0

如何解决这里映射用于批量反向地理编码位置的 API 每次都在已完成的作业上返回 SuccessCount 0

我们正在努力实现的目标

根据 https://developer.here.com/documentation/batch-geocoder/dev_guide/topics/quick-start-batch-geocode.html 获取多个地址的地理坐标

环境

截至今天(2021 年 7 月 27 日),我们使用的是最新的 HERE Batch Geocoder API https://developer.here.com/documentation/batch-geocoder/dev_guide/topics/api-reference.html

我们使用的是官方端点 https://batch.geocoder.ls.hereapi.com/6.2/jobs/,我们使用的是 apiKey,即我们不使用 app_id/app_code 作为身份验证方法

我们的 POST 在我们的 Postman 项目中是这样的:

https://batch.geocoder.ls.hereapi.com/6.2/jobs?apiKey={{here-rest-api-key}}&indelim=%7C&outdelim=%7C&action=run&outcols=displayLatitude%2CdisplayLongitude%2Ccity%2Cstate%2Ccountry&outputcombined=true&maxresults=500&gen=8&header=true

问题

发送 Batch 请求后,API 端点以 SUCCESS(无凭据错误)响应:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
    <Response>
        <MetaInfo>
            <RequestId>0FXztndLCKfpPFuOjGiGruNKcKXHIxpZ</RequestId>
        </MetaInfo>
        <Status>accepted</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>

这是 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
0004|One Main Street Cambridge MA 02142|USA
0005|200 S Mathilda Ave Sunnyvale CA 94086|USA
0006|45492 Via Jaca Temecula CA|USA
0007|marchant Pereira 1171 Providencia|CHL
0008|Los Alamos 1294 Santiago Centro|CHL
0009|Avenida Las Condes 12461 Las Condes|CHL
0010|Avenida Tulum 40 Cancun|MEX

几秒钟后,检查作业状态后,我们得到以下结果:

https://batch.geocoder.ls.hereapi.com/6.2/jobs/0FXztndLCKfpPFuOjGiGruNKcKXHIxpZ?action=status&apiKey={{here-rest-api-key}}

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
    <Response>
        <MetaInfo>
            <RequestId>0FXztndLCKfpPFuOjGiGruNKcKXHIxpZ</RequestId>
        </MetaInfo>
        <Status>completed</Status>
        <JobStarted>2021-07-27T18:52:52.000Z</JobStarted>
        <JobFinished>2021-07-27T18:52:55.000Z</JobFinished>
        <TotalCount>10</TotalCount>
        <ValidCount>10</ValidCount>
        <InvalidCount>0</InvalidCount>
        <ProcessedCount>10</ProcessedCount>
        <PendingCount>0</PendingCount>
        <SuccessCount>0</SuccessCount>
        <ErrorCount>10</ErrorCount>
    </Response>
</ns2:SearchBatch>

这意味着我们的请求是有效的,它处理了 10 条记录,这 10 条记录是有效的,但是......我们仍然得到 0 SuccessCount 和 10 ErroCount(没有项目被成功地反向地理编码)。

当我们获取工作结果 https://batch.geocoder.ls.hereapi.com/6.2/jobs/{{here-id-job}}/result?apiKey={{here-rest-api-key}} 时,我们会得到带有空字段的结果:

recId|SeqNumber|seqLength|displayLatitude|displayLongitude|city|state|country
0001|0|0|||||DEU
0002|0|0|||||DEU
0003|0|0|||||USA
0004|0|0|||||USA
0005|0|0|||||USA
0006|0|0|||||USA
0007|0|0|||||CHL
0008|0|0|||||CHL
0009|0|0|||||CHL
0010|0|0|||||MEX

我尝试了不同的 Body 请求,在每种情况下我都得到 100% ValidCount 但 100% ErrorCount。

根据他们的定价,免费帐户支持批量请求。 https://developer.here.com/pricing?planId=Freemium-Basic&fromFree=true&period=monthly#plan-details

有人遇到过这个问题吗?我们在哪里遗漏了什么?

解决方法

对于可能遇到相同问题的人,我们通过使用不同的 Field delimiter in the input data (indelim) 解决了问题。

HERE 上的所有 examplesGuide 都使用 |(管道,URL 编码:%7C),但我们的一位开发人员指出管道通常意味着 API 数据交换出现问题.

因此我们将 indelim 更改为 %3B(为了保持一致性,我们还将 outdelim 更改为 %3B),因此我们的 POST URL 如下所示:

https://batch.geocoder.ls.hereapi.com/6.2/jobs?apiKey={{here-rest-api-key}}&indelim=%3B&outdelim=%3B&action=run&outcols=displayLatitude%2CdisplayLongitude%2Ccity%2Cstate%2Ccountry&outputcombined=true&header=true

我们将 POST Body 从:

recId|searchText|country 
1|425 W Randolph St,Chicago Illinois 60606|USA 
2|31 St James Ave Boston MA 02116|USA 
3|10115 Berlin Invalidenstrasse 117|DEU

到:

recId;searchText;country 
1;425 W Randolph St,Chicago Illinois 60606;USA 
2;31 St James Ave Boston MA 02116;USA 
3;10115 Berlin Invalidenstrasse 117;DEU
...

它的作用就像一个魅力!

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
    <Response>
        <MetaInfo>
            <RequestId>JOBID</RequestId>
        </MetaInfo>
        <Status>completed</Status>
        <JobStarted>2021-07-28T17:37:38.000Z</JobStarted>
        <JobFinished>2021-07-28T17:37:45.000Z</JobFinished>
        <TotalCount>428</TotalCount>
        <ValidCount>428</ValidCount>
        <InvalidCount>0</InvalidCount>
        <ProcessedCount>428</ProcessedCount>
        <PendingCount>0</PendingCount>
        <SuccessCount>428</SuccessCount>
        <ErrorCount>0</ErrorCount>
    </Response>
</ns2:SearchBatch>

希望这对使用 HERE Batch Geocoder API 的人有所帮助:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。