How can you tell when an Android device has a Geocoder backend service?

前端 未结 2 1479
一个人的身影
一个人的身影 2021-01-14 21:03

According to the Geocoder documentation, the class provides methods into a backend service which may or may not exist on the device. If the geocoder doesn\'t exist on the d

2条回答
  •  深忆病人
    2021-01-14 21:37

    Strictly speaking there could be another backend installed, just try if a geocoder is present

        final Geocoder geocoder = new Geocoder(this);
        final String locName = "1600 Amphitheatre Parkway, Mountain View, CA";
        try {
            final List
    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(); }

提交回复
热议问题