Geocoder
AMap.Geocoder
Geocoding and reverse geocoding class, used for conversion between address descriptions and latitude/longitude coordinates. Users can obtain query results through callback functions. Construct a geocoding and reverse geocoding object, and set its properties through GeocoderOptions.
new AMap.Geocoder(opts: GeocoderOptions)Parameter
options (GeocoderOptions): Geocoding and reverse geocoding parameters
Demo
AMap.plugin("AMap.Geocoder", function () {
var geocoder = new AMap.Geocoder({
radius: 1000,
extensions: "all",
});
var lnglat = [-73.98751,40.74129];
geocoder.getAddress(lnglat, function (status, result) {
if (status === "complete" && result.info === "OK") {
// result is the corresponding detailed geographic information
}
});
});Method
getLocation(keyword, cbk)
Convert address information into Gaode latitude and longitude coordinates
Parameter:
keyword (String) Keyword
cbk (GeocoderCallback) Callback function
Demo:
var address = "9, Madison Avenue, 曼哈顿, 纽约, 纽约州, 美国";
geocoder.getLocation(address, function (status, result) {
if (status === "complete" && result.info === "OK") {
// result is the corresponding detailed geographic information
}
});setCity(city)
When geocoding, set the city for the address description
Parameter: city (String) City
Demo:
geocoder.setCity("010");getAddress(location, cbk)
Convert latitude and longitude coordinates into structured address information
Parameter:
location(LngLat | Array<LngLat>) Given coordinates
cbk (ReGeocoderCallback) Callback function
Demo:
var lnglat = [116.396574, 39.992706];
geocoder.getAddress(lnglat, function (status, result) {
if (status === "complete" && result.info === "OK") {
// result is the corresponding detailed geographic information
}
});