Added in API level 1

Geocoder

class Geocoder
kotlin.Any
   ↳ android.location.Geocoder

A class for handling geocoding and reverse geocoding. Geocoding is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinate. Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a (partial) address. The amount of detail in a reverse geocoded location description may vary, for example one might contain the full street address of the closest building, while another might contain only a city name and postal code. The Geocoder class requires a backend service that is not included in the core android framework. 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.

Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do not use this API for any safety-critical or regulatory compliance purpose.

Summary

Nested classes
abstract

A listener for asynchronous geocoding results.

Public constructors
Geocoder(context: Context)

Constructs a Geocoder localized for the default locale.

Geocoder(context: Context, locale: Locale)

Constructs a Geocoder localized for the given locale.

Public methods
MutableList<Address!>?
getFromLocation(latitude: Double, longitude: Double, maxResults: Int)

Returns an array of Addresses that attempt to describe the area immediately surrounding the given latitude and longitude.

Unit
getFromLocation(latitude: Double, longitude: Double, maxResults: Int, listener: Geocoder.GeocodeListener)

Provides an array of Addresses that attempt to describe the area immediately surrounding the given latitude and longitude.

MutableList<Address!>?
getFromLocationName(locationName: String, maxResults: Int)

Returns an array of Addresses that attempt to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", and so forth.

Unit
getFromLocationName(locationName: String, maxResults: Int, listener: Geocoder.GeocodeListener)

Provides an array of Addresses that attempt to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", and so forth.

MutableList<Address!>?
getFromLocationName(locationName: String, maxResults: Int, lowerLeftLatitude: Double, lowerLeftLongitude: Double, upperRightLatitude: Double, upperRightLongitude: Double)

Returns an array of Addresses that attempt to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", and so forth.

Unit
getFromLocationName(locationName: String, maxResults: Int, lowerLeftLatitude: Double, lowerLeftLongitude: Double, upperRightLatitude: Double, upperRightLongitude: Double, listener: Geocoder.GeocodeListener)

Returns an array of Addresses that attempt to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", and so forth.

static Boolean

Returns true if there is a geocoder implementation present that may return results.

Public constructors

Geocoder

Added in API level 1
Geocoder(context: Context)

Constructs a Geocoder localized for the default locale.

Parameters
context Context: This value cannot be null.

Geocoder

Added in API level 1
Geocoder(
    context: Context,
    locale: Locale)

Constructs a Geocoder localized for the given locale.

Parameters
context Context: This value cannot be null.
locale Locale: This value cannot be null.

Public methods

getFromLocation

Added in API level 1
Deprecated in API level 33
fun getFromLocation(
    latitude: Double,
    longitude: Double,
    maxResults: Int
): MutableList<Address!>?

Deprecated: Use getFromLocation(double,double,int,android.location.Geocoder.GeocodeListener) instead to avoid blocking a thread waiting for results.

Returns an array of Addresses that attempt to describe the area immediately surrounding the given latitude and longitude. The returned addresses should be localized for the locale provided to this class's constructor.

Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do NOT use this API for any safety-critical or regulatory compliance purposes.

Warning: This API may hit the network, and may block for excessive amounts of time, up to 60 seconds or more. It's strongly encouraged to use the asynchronous version of this API. If that is not possible, this should be run on a background thread to avoid blocking other operations.

Parameters
latitude Double: the latitude a point for the search Value is between -90D and 90D inclusive
longitude Double: the longitude a point for the search Value is between -180D and 180D inclusive
maxResults Int: max number of addresses to return. Smaller numbers (1 to 5) are recommended
Return
MutableList<Address!>? a list of Address objects. Returns null or empty list if no matches were found or there is no backend service available.
Exceptions
java.lang.IllegalArgumentException if latitude or longitude is invalid
java.io.IOException if there is a failure

getFromLocation

Added in API level 33
fun getFromLocation(
    latitude: Double,
    longitude: Double,
    maxResults: Int,
    listener: Geocoder.GeocodeListener
): Unit

Provides an array of Addresses that attempt to describe the area immediately surrounding the given latitude and longitude. The returned addresses should be localized for the locale provided to this class's constructor.

Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do NOT use this API for any safety-critical or regulatory compliance purposes.

Parameters
latitude Double: the latitude a point for the search Value is between -90D and 90D inclusive
longitude Double: the longitude a point for the search Value is between -180D and 180D inclusive
maxResults Int: max number of addresses to return. Smaller numbers (1 to 5) are recommended
listener Geocoder.GeocodeListener: a listener for receiving results This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if latitude or longitude is invalid

getFromLocationName

Added in API level 1
Deprecated in API level 33
fun getFromLocationName(
    locationName: String,
    maxResults: Int
): MutableList<Address!>?

Deprecated: Use getFromLocationName(java.lang.String,int,android.location.Geocoder.GeocodeListener) instead to avoid blocking a thread waiting for results.

Returns an array of Addresses that attempt to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", and so forth. The returned addresses should be localized for the locale provided to this class's constructor.

Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do NOT use this API for any safety-critical or regulatory compliance purposes.

Warning: This API may hit the network, and may block for excessive amounts of time, up to 60 seconds or more. It's strongly encouraged to use the asynchronous version of this API. If that is not possible, this should be run on a background thread to avoid blocking other operations.

Parameters
locationName String: a user-supplied description of a location This value cannot be null.
maxResults Int: max number of results to return. Smaller numbers (1 to 5) are recommended
Return
MutableList<Address!>? a list of Address objects. Returns null or empty list if no matches were found or there is no backend service available.
Exceptions
java.lang.IllegalArgumentException if locationName is null
java.io.IOException if there is a failure

getFromLocationName

Added in API level 33
fun getFromLocationName(
    locationName: String,
    maxResults: Int,
    listener: Geocoder.GeocodeListener
): Unit

Provides an array of Addresses that attempt to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", and so forth. The returned addresses should be localized for the locale provided to this class's constructor.

Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do NOT use this API for any safety-critical or regulatory compliance purposes.

Parameters
locationName String: a user-supplied description of a location This value cannot be null.
maxResults Int: max number of results to return. Smaller numbers (1 to 5) are recommended
listener Geocoder.GeocodeListener: a listener for receiving results This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if locationName is null

getFromLocationName

Added in API level 1
Deprecated in API level 33
fun getFromLocationName(
    locationName: String,
    maxResults: Int,
    lowerLeftLatitude: Double,
    lowerLeftLongitude: Double,
    upperRightLatitude: Double,
    upperRightLongitude: Double
): MutableList<Address!>?

Deprecated: Use getFromLocationName(java.lang.String,int,double,double,double,double,android.location.Geocoder.GeocodeListener) instead to avoid blocking a thread waiting for results.

Returns an array of Addresses that attempt to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", and so forth. The returned addresses should be localized for the locale provided to this class's constructor.

You may specify a bounding box for the search results by including the latitude and longitude of the lower left point and upper right point of the box.

Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do NOT use this API for any safety-critical or regulatory compliance purposes.

Warning: This API may hit the network, and may block for excessive amounts of time, up to 60 seconds or more. It's strongly encouraged to use the asynchronous version of this API. If that is not possible, this should be run on a background thread to avoid blocking other operations.

Parameters
locationName String: a user-supplied description of a location This value cannot be null.
maxResults Int: max number of addresses to return. Smaller numbers (1 to 5) are recommended
lowerLeftLatitude Double: the latitude of the lower left corner of the bounding box Value is between -90D and 90D inclusive
lowerLeftLongitude Double: the longitude of the lower left corner of the bounding box Value is between -180D and 180D inclusive
upperRightLatitude Double: the latitude of the upper right corner of the bounding box Value is between -90D and 90D inclusive
upperRightLongitude Double: the longitude of the upper right corner of the bounding box Value is between -180D and 180D inclusive
Return
MutableList<Address!>? a list of Address objects. Returns null or empty list if no matches were found or there is no backend service available.
Exceptions
java.lang.IllegalArgumentException if any latitude or longitude is invalid
java.io.IOException if there is a failure

getFromLocationName

Added in API level 33
fun getFromLocationName(
    locationName: String,
    maxResults: Int,
    lowerLeftLatitude: Double,
    lowerLeftLongitude: Double,
    upperRightLatitude: Double,
    upperRightLongitude: Double,
    listener: Geocoder.GeocodeListener
): Unit

Returns an array of Addresses that attempt to describe the named location, which may be a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", and so forth. The returned addresses should be localized for the locale provided to this class's constructor.

You may specify a bounding box for the search results by including the latitude and longitude of the lower left point and upper right point of the box.

Warning: Geocoding services may provide no guarantees on availability or accuracy. Results are a best guess, and are not guaranteed to be meaningful or correct. Do NOT use this API for any safety-critical or regulatory compliance purposes.

Parameters
locationName String: a user-supplied description of a location This value cannot be null.
maxResults Int: max number of addresses to return. Smaller numbers (1 to 5) are recommended
lowerLeftLatitude Double: the latitude of the lower left corner of the bounding box Value is between -90D and 90D inclusive
lowerLeftLongitude Double: the longitude of the lower left corner of the bounding box Value is between -180D and 180D inclusive
upperRightLatitude Double: the latitude of the upper right corner of the bounding box Value is between -90D and 90D inclusive
upperRightLongitude Double: the longitude of the upper right corner of the bounding box Value is between -180D and 180D inclusive
listener Geocoder.GeocodeListener: a listener for receiving results This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if any latitude or longitude is invalid

isPresent

Added in API level 9
static fun isPresent(): Boolean

Returns true if there is a geocoder implementation present that may return results. If true, there is still no guarantee that any individual geocoding attempt will succeed.