Geocoderpublic final class Geocoder extends Object 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. |
Fields Summary |
---|
private static final String | TAG | private GeocoderParams | mParams | private ILocationManager | mService |
Constructors Summary |
---|
public Geocoder(android.content.Context context, Locale locale)Constructs a Geocoder whose responses will be localized for the
given Locale.
if (locale == null) {
throw new NullPointerException("locale == null");
}
mParams = new GeocoderParams(context, locale);
IBinder b = ServiceManager.getService(Context.LOCATION_SERVICE);
mService = ILocationManager.Stub.asInterface(b);
| public Geocoder(android.content.Context context)Constructs a Geocoder whose responses will be localized for the
default system Locale.
this(context, Locale.getDefault());
|
Methods Summary |
---|
public java.util.List | getFromLocation(double latitude, double longitude, int maxResults)Returns an array of Addresses that are known to describe the
area immediately surrounding the given latitude and longitude.
The returned addresses will be localized for the locale
provided to this class's constructor.
The returned values may be obtained by means of a network lookup.
The results are a best guess and are not guaranteed to be meaningful or
correct. It may be useful to call this method from a thread separate from your
primary UI thread.
if (latitude < -90.0 || latitude > 90.0) {
throw new IllegalArgumentException("latitude == " + latitude);
}
if (longitude < -180.0 || longitude > 180.0) {
throw new IllegalArgumentException("longitude == " + longitude);
}
try {
List<Address> results = new ArrayList<Address>();
String ex = mService.getFromLocation(latitude, longitude, maxResults,
mParams, results);
if (ex != null) {
throw new IOException(ex);
} else {
return results;
}
} catch (RemoteException e) {
Log.e(TAG, "getFromLocation: got RemoteException", e);
return null;
}
| public java.util.List | getFromLocationName(java.lang.String locationName, int maxResults)Returns an array of Addresses that are known 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", etc.. The
returned addresses will be localized for the locale provided to
this class's constructor.
The query will block and returned values will be obtained by means of a network lookup.
The results are a best guess and are not guaranteed to be meaningful or
correct. It may be useful to call this method from a thread separate from your
primary UI thread.
if (locationName == null) {
throw new IllegalArgumentException("locationName == null");
}
try {
List<Address> results = new ArrayList<Address>();
String ex = mService.getFromLocationName(locationName,
0, 0, 0, 0, maxResults, mParams, results);
if (ex != null) {
throw new IOException(ex);
} else {
return results;
}
} catch (RemoteException e) {
Log.e(TAG, "getFromLocationName: got RemoteException", e);
return null;
}
| public java.util.List | getFromLocationName(java.lang.String locationName, int maxResults, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude)Returns an array of Addresses that are known 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", etc.. The
returned addresses will 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.
The query will block and returned values will be obtained by means of a network lookup.
The results are a best guess and are not guaranteed to be meaningful or
correct. It may be useful to call this method from a thread separate from your
primary UI thread.
if (locationName == null) {
throw new IllegalArgumentException("locationName == null");
}
if (lowerLeftLatitude < -90.0 || lowerLeftLatitude > 90.0) {
throw new IllegalArgumentException("lowerLeftLatitude == "
+ lowerLeftLatitude);
}
if (lowerLeftLongitude < -180.0 || lowerLeftLongitude > 180.0) {
throw new IllegalArgumentException("lowerLeftLongitude == "
+ lowerLeftLongitude);
}
if (upperRightLatitude < -90.0 || upperRightLatitude > 90.0) {
throw new IllegalArgumentException("upperRightLatitude == "
+ upperRightLatitude);
}
if (upperRightLongitude < -180.0 || upperRightLongitude > 180.0) {
throw new IllegalArgumentException("upperRightLongitude == "
+ upperRightLongitude);
}
try {
ArrayList<Address> result = new ArrayList<Address>();
String ex = mService.getFromLocationName(locationName,
lowerLeftLatitude, lowerLeftLongitude, upperRightLatitude, upperRightLongitude,
maxResults, mParams, result);
if (ex != null) {
throw new IOException(ex);
} else {
return result;
}
} catch (RemoteException e) {
Log.e(TAG, "getFromLocationName: got RemoteException", e);
return null;
}
| public static boolean | isPresent()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.
IBinder b = ServiceManager.getService(Context.LOCATION_SERVICE);
ILocationManager lm = ILocationManager.Stub.asInterface(b);
try {
return lm.geocoderIsPresent();
} catch (RemoteException e) {
Log.e(TAG, "isPresent: got RemoteException", e);
return false;
}
|
|