Geocoder's isPresent() method always returns false

前端 未结 3 1671
醉话见心
醉话见心 2020-12-06 21:36

I had written a simple Activity to test presence of Geocoder, calling Geocoder.isPresent() always returns false.

Class:

public class LocationTestActi         


        
相关标签:
3条回答
  • 2020-12-06 21:57

    Actually the Geocoder need a Service running in the background by the framework.

    From the documentation:

    The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.

    so if we look at the documentation of isPresent(), it states.

    Returns true if the Geocoder methods getFromLocation and getFromLocationName are implemented. Lack of network connectivity may still cause these methods to return null or empty lists.

    Note: keep in mind that isPresent() is not available in Pre-Api 9 plateforms.

    0 讨论(0)
  • 2020-12-06 22:05

    Testing this code in Emulator or device ? I have faced same problem when I was using GeoCoder on 2.2 emulator. But code works fine on 2.1 emulator. Try to use 2.1

    And code must be running fine on device.

    0 讨论(0)
  • 2020-12-06 22:19

    Use AsyncTask to fetch coordinates from server using geocoder. For example, getFromLocationName() should be called using AsyncTask. UI thread (main activity) does not allow the tasks which take too much time, hence the method returns empty list.

    0 讨论(0)
提交回复
热议问题