Document Maps JavaScript API Reference Manual Geocoding Geocoder

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

Attribute

Type

Description

city

string

City. During geocoding, set the city where the address description is located. Optional values: citycode, adcode. City code table

radius

number

During reverse geocoding, the range centered on the given coordinates, in meters.

 Value range: 0 - 3000. 

Default: 1000

lang

string

Set language type. 

Optional values: zh_cn (Chinese), en (English). 

Default: zh_cn (Chinese)

batch

boolean

Whether to batch query; 

when batch is set to false, only the first record is returned

extensions

string

When reverse geocoding, the level of detail in the returned information defaults to 'base', returning basic address information; set to 'all', it returns address information along with nearby POIs, roads, road intersections, etc.

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 (StringKeyword

cbk (GeocoderCallbackCallback 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

Parametercity (StringCity

Demo:

geocoder.setCity("010");

getAddress(location, cbk)

Convert latitude and longitude coordinates into structured address information

Parameter:

location(LngLat | Array<LngLat>Given coordinates

cbk (ReGeocoderCallbackCallback 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
  }
});