代码之家  ›  专栏  ›  技术社区  ›  Dan Lew

你如何判断Android设备何时有Geocoder后端服务?

  •  1
  • Dan Lew  · 技术社区  · 16 年前

    Geocoder documentation ,该类向后端服务提供方法,该服务可能存在于设备上,也可能不存在于设备上。如果设备上不存在地理编码器,理论上,地理编码请求将不会返回任何结果。然而,如何区分由于没有后端地理编码器服务而没有结果与由于位置没有意义而没有结果?

    包括地理编码器?

    2 回复  |  直到 16 年前
        1
  •  2
  •   RickNotFred    16 年前

    根据 Google Maps docs ,“谷歌地图API提供了一个用于地理编码地址的客户端地理编码器”。所以我想说,既然你需要谷歌地图API,你就需要一个地理编码器。

        2
  •  5
  •   Diego Torres Milano    16 年前

        final Geocoder geocoder = new Geocoder(this);
        final String locName = "1600 Amphitheatre Parkway, Mountain View, CA";
        try {
            final List<Address> list = geocoder.getFromLocationName(locName, 1);
            if ( ! (list == null || list.isEmpty()) ) {
                final Address address = list.get(0);
                System.out.println("Geocoder backend present, (lat,lon) = (" + address.getLatitude() + ", " + address.getLongitude() + ")");
            }
            else {
                System.out.println("Geocoder backend not present");
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }