【问题标题】:Reverse geocoding not available for China反向地理编码不适用于中国
【发布时间】:2019-07-29 12:03:48
【问题描述】:

嘿,我正在使用 here.com API 进行反向地理编码。但是,当我尝试根据纬度和经度获取中国的位置时,我得到城市的“未定义”。

那是什么?

是否有人知道替代 here.com 的反向地理编码的替代方法,效果好、速度快且价格合理?

谢谢。

【问题讨论】:

  • 对于中国,您最好使用本地服务提供商,例如腾讯地图。他们有一个Geocoder 服务和一个与谷歌地图提供的 API 非常相似的 API……

标签: geocoding here-api reverse-geocoding


【解决方案1】:

中国许多供应商的数据覆盖范围充其量是参差不齐的。尝试一些,看看什么对你有用。 https://geocode.xyz/CNhttps://geocode.earth 是两种选择。

【讨论】:

    【解决方案2】:

    你可以试试 Open Street Map Nominatim Webservice,它会为你执行地理编码和反向地理编码,不过我会查看使用条款:

    以下是 Node.js 中的示例(必须安装 request 和 request-promise-native):

    const rp = require('request-promise-native');
    
    async function testReverseGeocode(latitude, longitude) {
        const options = {
            url: "https://nominatim.openstreetmap.org/reverse",
            qs: { 
                lat: latitude,
                lon: longitude,
                format: 'json'
            },
            json: true,
            headers: {
                'User-Agent': "Node.js",
                'Accept-Language': 'en-GB,en;q=0.7,en-US;q=0.3'
            }, 
        };
        let result = await rp(options);
        console.log("Result: ", result);
    }
    
    testReverseGeocode(31.2304, 121.4737);
    

    如果您愿意使用付费服务,Google Geocoding API 非常好,如果您不执行大量请求,也不会很贵:

    const rp = require('request-promise-native');
    
    async function testReverseGeocodeGoogle(latitude, longitude) {
        const options = {
            url: `https://maps.googleapis.com/maps/api/geocode/json?latlng=${latitude},${longitude}`,
            qs: { 
                key: API_KEY
            },
            json: true
        };
        let result = await rp(options);
        console.log("Result: ", result);
    }
    
    testReverseGeocodeGoogle(31.2304, 121.4737);
    

    【讨论】:

    • 这两项服务在中国的表现如何,因为这是 OP 所要求的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    相关资源
    最近更新 更多