public final class GeoConvert extends Object
This class allows your application to convert the longitude and latitude of a location to the address information or contrariwise. The conversion result is carried in an address list, which includes information such as the longitude and latitude, city name, country code, and administrative region name.
The conversion function is implemented by the backend service. Your application will receive an empty address list if the backend service does not support this function or return the conversion result.
You can use the isGeoAvailable() method to check whether the backend service supports
the conversion function.
GeoAddress| 构造器 | 说明 |
|---|---|
GeoConvert() |
Creates a
GeoConvert instance with default parameters. |
GeoConvert(Locale locale) |
Creates a
GeoConvert instance with customized parameters. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
List<GeoAddress> |
getAddressFromLocation(double latitude,
double longitude,
int maxItems) |
Obtains the possible address list based on the specified longitude and latitude coordinates.
|
List<GeoAddress> |
getAddressFromLocationName(String description,
double minLatitude,
double minLongitude,
double maxLatitude,
double maxLongitude,
int maxItems) |
Obtains the possible address list based on the specified location information and geographic region.
|
List<GeoAddress> |
getAddressFromLocationName(String description,
int maxItems) |
Obtains the possible address list based on the specified location information.
|
boolean |
isGeoAvailable() |
Checks whether the system supports the conversion between geographic location and address information.
|
public GeoConvert(Locale locale) throws IllegalArgumentException
GeoConvert instance with customized parameters.
Specifically, this method uses the locale parameters set by
Locale to initialize the GeoConvert object.
locale - Specifies the locale parameter. The value must not be null.IllegalArgumentException - Throws this exception if Locale is null.public GeoConvert()
GeoConvert instance with default parameters.
Specifically, this method uses the default locale parameters obtained by
Locale.getDefault() to initialize the GeoConvert object.
public boolean isGeoAvailable()
true if conversion is supported; returns false otherwise.public List<GeoAddress> getAddressFromLocation(double latitude, double longitude, int maxItems) throws IOException
The language of returned address descriptions is determined by the Locale object
in GeoConvert.
The number of items on the address list is subject to the actual address information returned by the backend service but will not exceed the limit you specified.
latitude - Specifies the latitude. The value range is [-90,90], in unit of degrees.longitude - Specifies the longitude. The value range is [-180,180], in unit of degrees.maxItems - Specifies the maximum length of the returned address list. The recommended value range is 1-5.
The default value 1 will be used if the specified value is smaller than 1.IllegalArgumentException - Throws this exception if the latitude is not within the range [-90,90] or
the longitude is not within the range [-180,180].IOException - Throws this exception if the network is unavailable or an I/O exception occurs.GeoAddresspublic List<GeoAddress> getAddressFromLocationName(String description, int maxItems) throws IOException
For example, the location information can be Beijing, Beijing Capital International Airport, etc.
The language of returned address descriptions is determined by the Locale object
in GeoConvert.
The number of items on the address list is subject to the actual address information returned by the backend service but will not exceed the limit you specified.
description - Specifies the location information.maxItems - Specifies the maximum length of the returned address list. The recommended value range is 1-5.
The default value 1 will be used if the specified value is smaller than 1.IllegalArgumentException - Throws this exception if description is null.IOException - Throws this exception if the network is unavailable or an I/O exception occurs.GeoAddresspublic List<GeoAddress> getAddressFromLocationName(String description, double minLatitude, double minLongitude, double maxLatitude, double maxLongitude, int maxItems) throws IOException
You can specify a geographic region to distinguish geographic locations with the same name. This can improve the accuracy of the returned address list.
The language of returned address descriptions is determined by the Locale object
in GeoConvert.
The number of items on the address list is subject to the actual address information returned by the backend service but will not exceed the limit you specified.
description - Specifies the location information.minLatitude - Indicates the minimum latitude of a rectangular area. The value range is [-90, 90].minLongitude - Indicates the minimum longitude of a rectangular area. The value range is [-180, 180].maxLatitude - Indicates the maximum latitude of a rectangular area. The value range is [-90, 90].maxLongitude - Indicates the maximum longitude of a rectangular area. The value range is [-180, 180].maxItems - Specifies the maximum length of the returned address list.
The recommended value range is 1-5. The default value 1 will be used
if the specified value is smaller than 1.IllegalArgumentException - Throws this exception if description is null.IllegalArgumentException - Throws this exception if the boundary latitude of the rectangular area
is not within the range [-90,90].IllegalArgumentException - Throws this exception if the boundary longitude of the rectangular area
is not within the range [-180,180].IOException - Throws this exception if the network is unavailable or an I/O exception occurs.GeoAddress