Geocoder's isPresent() method always returns false

…衆ロ難τιáo~ 提交于 2019-11-28 01:24:05

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.

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.

user3473546

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.

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