android - Mapbox 反向地理编码并不总是返回结果
问题描述
我在 mapbox 上尝试反向地理编码示例
一切正常。但问题是当我替换我当前的位置时,它不会返回结果。我认为 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();
}
解决方案
目前无法将自定义 POI 添加到支持 Geocoding API 的数据中,但解决方法是使用Tilequery API。此 API 根据与特定地理坐标的接近程度从矢量切片中检索特征。您可以通过以下工作流程使用自定义 POI 模拟反向地理编码功能:
- 创建一个包含自定义 POI 的图块集。也就是说,将您的数据上传为 tileset。
- 检索要用于反向地理编码的点的地理坐标。
- 调用 Tilequery API,其中 radius 为 0,tileset_id 是您在步骤 1 中创建的图块集的 id,{lon},{lat} 是在步骤 2 中检索到的经度和纬度。有关每个参数的更多详细信息可以在这里找到。
我建议通过本教程学习使用 Tilequery API 制作健康食品查找器,以获得更多关于如何使用 API 进行自定义 POI 反向地理编码的直觉。Tilequery API 游乐场也是交互式实验的绝佳资源。
如果有不清楚的地方,请告诉我!
推荐阅读
- unity3d - 用户使用全息透镜扫描海报。3D 内容将覆盖在海报上
- c# - Using AWS SDK on .net with localstack (TransferUtility/S3 - setting endpoint)
- json - 我应该使用 JSend 来包装 json ajax 响应,还是有更标准的标准?
- java - 带有公司代理的测试容器
- php - How to find the domain is whether HTTP or HTTPS (with or without WWW) using PHP?
- css - Css我如何从inspector中找到一个css文件
- laravel - 我如何验证 Laravel 5.4 中的电子邮件列表
- opc-ua - Livetime / uniqueness of NodeId (How to manage NodeIds for dynamic nodes)
- php - Using functions.php or something instead of content-single-product.php and content-product.php
- javascript - 从 promise 返回回调的结果