Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android Geocoder work only with internet connection?

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" />
like image 786
user2328149 Avatar asked Apr 28 '13 02:04

user2328149


People also ask

How does Android Geocoder work?

The Android API contains a Geocoder class that can use either a location name or a location's latitude and longitude values to get further details about an address (it can perform both forward and reverse geocoding). The returned address details include address name, country name, country code, postal code and more.

Is Android location Geocoder free?

The Geocoding API uses a pay-as-you-go pricing model.

How can I get full address from latitude and longitude in Android?

The short story is you need to do: Geocoder geocoder = new Geocoder(this, Locale. getDefault()); List<Address> addresses = geocoder. getFromLocation(lat, lng, 1);

What is the difference between geocoding and reverse geocoding?

Reverse-Geocoding is a process used to convert coordinates (latitude and longitude) to human-readable addresses. This is not exactly the opposite of Geocoding. In Geocoding, the Place is associated with a name and fixed coordinates.


1 Answers

Yes. Do you know how much data is needed for the full geocoder? You aren't storing that on a cellphone.

like image 152
Gabe Sechan Avatar answered Oct 22 '22 02:10

Gabe Sechan