java - 如何从开放位置代码中获取完整代码

标签 java android coordinates open-location-code

我正在尝试从简短的开放位置代码中获取完整的开放位置代码,我做错了什么?我在我的 android 项目中使用 Java Open Location Code -library。

        // 63.7740574, 23.9011008

        // This is an full olc (I searched it from web)
        // input = "9GM5QWF2+JC";

        // This is an short olc (also searched from the web)
        // input = "QWF2+JC";

        // And this is an olc which is copied to clipboard from google maps application
        input = "QWF2+JC Hautala";

        boolean isFullCode = OpenLocationCode.isFullCode(input);
        boolean isShortCode = OpenLocationCode.isShortCode(input);

        if (isFullCode || isShortCode)
        {
            OpenLocationCode olc = new OpenLocationCode(input);

            Double lat = olc.decode().getCenterLatitude(); // Crashes here if we are parsing input to short code
            Double lng = olc.decode().getCenterLatitude(); // But doesn't crash if we are using full lenght code

            result = new LatLng(lat, lng);
        }

最佳答案

完整代码看起来像 8FVC9G8F+6W - 也就是说,它在“+”之前有八位数字。

短代码是一样的,只是“+”前的数字更少(通常是四位)。

"QWF2+JC Hautala"是带有地区的短代码。要将其转换为完整代码,您需要:

  1. 将其拆分为“QWF2+JC”和“Hautala”;
  2. 使用您选择的地理编码器将“Hautala”地理编码为纬度和经度;
  3. 使用 OpenLocationCode 对象的 recover() 方法恢复完整代码。

另一种方法是将它扔到 Google Geocoding API 处(您需要获得一个 API key )。

关于java - 如何从开放位置代码中获取完整代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52833307/

相关文章:

python - 如何将字符串拆分为两个数字

java - jfilechooser,保存多个文件,图像?

android - 无法从 Android 中的 SQLite 的 .db 文件收集数据

r - 在地理上聚合 worldclim 的单元格,使用 30 秒分辨率来估计 10 分钟分辨率的标准偏差

android - 如果我不想关闭我的应用程序,如何从 ANDROID 应用程序中的后退或主页按钮生存

android - 在viewpager中可以实现这种效果吗?

ios - iPhone 像素坐标问题

java - 常见的 Java 内存/引用泄漏模式?

java - 使用 mailto : 时 Outlook 不处理多字节字符

java - 限制java8并行流的CPU使用率/Java 8并行流的高CPU使用率