The Geocoder isPresent () method always returns false.

I wrote a simple activity to check for the presence of Geocoder, calling Geocoder.isPresent () always returns false.

Grade:

public class LocationTestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Log.d( "LocationTestActivity", "Geocoder.isPresent : " + Geocoder.isPresent() ); } } 


AndroidManifest.xml ALSO has the following entries before the "application" element:

 <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 


Environment: Eclipse Indigo 3.7.1, ICS 4.0 emulator on XP Professional 2002 SP 3

Please help me understand:
1. Why does Geocoder.isPresent () always keep false?
2. What changes make Geocoder.isPresent () return true?

Many thanks!

+4
source share
3 answers

In fact, Geocoder requires a service running in the background using a framework.

From the documentation:

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

therefore, if we look at the isPresent() documentation, it will be indicated.

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

Note: Remember that isPresent() not available in Pre-Api 9 formats.

+5
source

Testing this code in an emulator or device? I faced the same problem when using GeoCoder on 2.2 emulator. But the code works fine on emulator 2.1. Try using 2.1

And the code should work fine on the device.

+1
source

Use AsyncTask to get coordinates from the server using geocoder . For example, getFromLocationName() should be called using AsyncTask . The user interface thread (the main action) does not allow you to perform tasks that take too long, so the method returns an empty list.

+1
source

Source: https://habr.com/ru/post/915164/


All Articles