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

二次信任 提交于 2019-12-01 09:43:56

问题


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 device, theoretically a geocode request will return no results. However, how can one differentiate between no results due to there being no backend geocoder service vs. there being no results because the location makes no sense?

My app already requires the Google Maps API, so perhaps this is a moot point; as a secondary question, does the Google Maps API always include a Geocoder?


回答1:


According to the Google Maps docs, "The Google Maps API provides a client geocoder for geocoding addresses". So I would say that since you are requiring the google maps API, you are requiring a geocoder.




回答2:


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<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();
    }


来源:https://stackoverflow.com/questions/2255020/how-can-you-tell-when-an-android-device-has-a-geocoder-backend-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!