android - 如何计算 Android Geocoder 结果的缩放级别

标签 android android-mapview google-geocoder

我正在使用 Android 的 Geocoder 来允许在我的基于 map 的应用程序中搜索位置。地理编码运行良好,应用程序成功地将 MapView 重新定位在地理编码结果上。问题是我不知道移动到新位置时使用什么缩放级别。 location_query 参数可以是一条街道,也可以是一个国家——我如何知道要放大多远才能显示结果位置?也就是说,我用什么替换 ???

public void goToPlace(String location_query) {

    List<Address> addresses;
    Geocoder gc = new Geocoder(_ctx);

    addresses = gc.getFromLocationName(location_query, 1);
    if (addresses != null) {
        Address a = addresses.get(0);
        int lat = (int) (a.getLatitude() * 1E6);
        int lon = (int) (a.getLongitude() * 1E6);
        mapController.animateTo(new GeoPoint(lat, lon));
        mapController.setZoom(???);
    }
}

最佳答案

我的想法是使用方法 getAddressLine 来选择适当的缩放级别。正如文档所说:

Returns a line of the address numbered by the given index (starting at 0), or null if no such line is present.

所以对于一个国家,它只返回 1 行地址,城市 2 行,街道 3 行。对于每种情况,您可以使用不同的缩放级别。

关于android - 如何计算 Android Geocoder 结果的缩放级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5682909/

相关文章:

java - Android - EditText 不可编辑且不可选择

android - 添加谷歌地图功能后无法实例化 Activity ComponentInfo

android - map View 使用 google Directions API 绘制方向 - 解码多段线

javascript - Google Maps API - 获取属性(property)边界数据

java - Android 操作栏覆盖并默认隐藏在 xml 中

android - android studio项目中出现gradle task错误

android - 在 gradle 中添加 kapt androidx room 会导致数据绑定(bind)错误

android - 带有加载器框架的 MapActivity

javascript - Google map + Google 本地搜索根据英国邮政编码生成纬度/经度

javascript - JS Geocoder 无法为 Google map 变量分配全局变量