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

Public constructors
Geocoder(context: Context!, locale: Locale!)

Constructs a Geocoder whose responses will be localized for the given Locale.

Geocoder(context: Context!)

Constructs a Geocoder whose responses will be localized for the default system 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.

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.

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.

static Boolean

Returns true if the Geocoder methods getFromLocation and getFromLocationName are implemented.

Public constructors

Geocoder

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

Constructs a Geocoder whose responses will be localized for the given Locale.

Parameters
context Context!: the Context of the calling Activity
locale Locale!: the desired Locale for the query results
Exceptions
java.lang.NullPointerException if Locale is null

Geocoder

Added in API level 1
Geocoder(context: Context!)

Constructs a Geocoder whose responses will be localized for the default system Locale.

Parameters
context Context!: the Context of the calling Activity

Public methods

getFromLocation

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

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. Results may be obtained by means of a network lookup and this method may take some time to return, and so should not be called on the main thread.

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
longitude Double: the longitude a point for the search
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 longitude is less than -180 or greater than 180
java.io.IOException if the network is unavailable or any other I/O problem occurs

getFromLocationName

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

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. Results may be obtained by means of a network lookup and this method may take some time to return, and so should not be called on the main thread.

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
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 the network is unavailable or any other I/O problem occurs

getFromLocationName

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

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. Results may be obtained by means of a network lookup and this method may take some time to return, and so should not be called on the main thread.

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
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
lowerLeftLongitude Double: the longitude of the lower left corner of the bounding box
upperRightLatitude Double: the latitude of the upper right corner of the bounding box
upperRightLongitude Double: the longitude of the upper right corner of the bounding box
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 longitude is less than -180 or greater than 180
java.io.IOException if the network is unavailable or any other I/O problem occurs

isPresent

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

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.