I'm trying to get the clicked address on a Google Map with the onMapLongClickListener(LatLng point), using the lat and the lng of the point and converting them in a address with a Geocoder.It works fine if I am connected to Internet, but if I'm not the app crashes because the getFromLocation method gives a null result. So I suppose that the Geocoder class works only with the connection is enabled.Is it so?And is there a way to get the adress staying offline?
That's the code of the method:
public void onMapLongClick(LatLng point) {
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(point.latitude, point.longitude, 1);
} catch (IOException e) {
e.printStackTrace();
}
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
String str = address + ", " + city + ", " + country;
gMap.addMarker(new MarkerOptions()
.position(point)
.title("Clicked Point")
.draggable(false)
.snippet(address + ", " + city + ", " + country));
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(50);
}
And these are the permissions:
<uses-permission android:name="com.example.mappine.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />