【问题标题】:Mapbox reverse geocoding does not always return a resultMapbox 反向地理编码并不总是返回结果
【发布时间】:2020-11-05 06:10:03
【问题描述】:

我在 mapbox 上尝试reverse geocoding example

一切正常。但问题是当我替换我当前的位置时,它不会返回结果。 我认为 mapbox 没有太多关于我所在地区的数据(我在越南)。假设我有一个坐标和地址数据集,是否可以添加我自己的地方

我的代码:

mapboxGeocoding = MapboxGeocoding.builder()
                .accessToken(getString(R.string.mapbox_access_token))
                .query(Point.fromLngLat(106.799142,10.875838))
                .geocodingTypes(GeocodingCriteria.TYPE_ADDRESS)
                .build();;

        mapboxGeocoding.enqueueCall(new Callback<GeocodingResponse>() {
            @Override
            public void onResponse(Call<GeocodingResponse> call, Response<GeocodingResponse> response) {

                List<CarmenFeature> results = response.body().features();

                if (results.size() > 0) {

                    // Log the first results Point.
                    //Point firstResultPoint = results.get(0).center();
                    String country=results.get(0).placeName();
                    Log.d("Geocoding",country);
                } else {

                    // No result for your request were found.

                    Toast.makeText(getApplicationContext(), "onResponse: No result found", Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onFailure(Call<GeocodingResponse> call, Throwable throwable) {
                throwable.printStackTrace();
            }
        });
    }
    @Override
    protected void onDestroy(){
        super.onDestroy();
        mapboxGeocoding.cancelCall();
    }

【问题讨论】:

    标签: android mapbox reverse-geocoding


    【解决方案1】:

    目前无法将自定义 POI 添加到支持地理编码 API 的数据中,但解决方法是使用 Tilequery API。此 API 根据与特定地理坐标的接近程度从矢量切片中检索特征。您可以通过以下工作流程使用自定义 POI 模拟反向地理编码功能:

    1. 创建一个包含自定义 POI 的图块集。即upload your data as a tileset
    2. 检索您要用于反向地理编码的点的地理坐标。
    3. 调用 Tilequery API,其中 radius 为 0,tileset_id 是您在第 1 步中创建的瓦片集的 id,{lon},{lat} 是在第 2 步中检索到的经度和纬度。关于每个的详细信息可以在here 找到这些参数。

    我建议通过此tutorial 使用 Tilequery API 制作健康食品查找器,以更直观地了解如何使用该 API 对自定义 POI 进行反向地理编码。 Tilequery API playground 也是交互式实验的绝佳资源。

    如果有不清楚的地方请告诉我!

    【讨论】:

    • 谢谢你的回答,我现在就试试。而且 tut 应用在某种程度上与我的应用非常相似
    猜你喜欢
    • 1970-01-01
    • 2012-05-05
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多