搜索、地址与定位 API
JS 0.1.0-alpha.37 · 2026-10-09。来源为当前源码生成的 TypeScript 声明。优先使用 load() 返回的 Namespace;底层类的 Client 参数由绑定构造器注入,业务不需自行创建。private/protected 成员不属于公开接入。
services
import { Callback, ServiceCallback, Client, Evented, LngLat, LngLatLike } from './core';
import { Map } from './map';
import { LocationAddressSession, AddressFields } from './location-address';
export interface Poi {
id: string;
name: string;
type: string;
kind?: 'poi' | 'building';
location: LngLat;
}
export interface SearchResult {
info: string;
poiList: {
count: number;
pois: Poi[];
};
datasetVersion: string;
}
export interface PlaceDetails extends Poi, SearchResult {
}
export interface SearchOptions {
pageIndex?: number;
pageSize?: number;
type?: string;
map?: Map;
}
export interface RouteStep {
roadId: string;
roadName: string;
startIndex: number;
endIndex: number;
distanceMeters: number;
roundabout: boolean;
road?: string;
distance?: number;
path?: LngLat[];
instruction?: string;
displayInstruction?: string;
action?: string;
orientation?: string;
duration?: number;
maneuver?: string;
}
export interface Route {
routeId: string;
datasetVersion: string;
distance: number;
time: number;
path: LngLat[];
steps: RouteStep[];
mode: 'preview';
guidanceMode?: 'geometry-based' | 'road-segments';
travelMode?: 'driving' | 'walking';
}
export interface DrivingResult {
routes: Route[];
info?: string;
start?: LngLat;
end?: LngLat;
}
/** Familiar policy names; values are our own wire contract, not AMap numeric constants. */
export declare const DrivingPolicy: Readonly<{
readonly LEAST_TIME: 'TIME';
readonly LEAST_DISTANCE: 'DISTANCE';
}>;
export declare class Service extends Evented {
constructor(client: Client);
getLanguage(): import("./language").SdkLanguage;
cancel(): void;
destroy(): void;
}
export declare class PlaceSearch extends Service {
constructor(client: Client, options?: SearchOptions);
setPageIndex(pageIndex: number): void;
setPageSize(pageSize: number): void;
search(keyword: string, callback?: ServiceCallback<SearchResult>): Promise<SearchResult>;
searchNearBy(keyword: string, center: LngLatLike, radius: number, callback?: ServiceCallback<SearchResult>): Promise<SearchResult>;
getDetails(id: string, callback?: ServiceCallback<PlaceDetails>): Promise<{
id: string;
name: string;
type: string;
kind?: 'poi' | 'building';
location: LngLat;
info: string;
poiList: {
count: number;
pois: Poi[];
};
datasetVersion: any;
}>;
clear(): void;
destroy(): void;
}
export interface AutoCompleteOptions {
input?: string | HTMLInputElement;
}
export declare class AutoComplete extends Service {
constructor(client: Client, options?: AutoCompleteOptions);
search(keyword: string, callback?: ServiceCallback<{
tips: Poi[];
count: number;
info: string;
}>): Promise<{
tips: any;
count: any;
info: string;
}>;
destroy(): void;
}
export declare class Driving extends Service {
setAvoidPolygons(areas: LngLatLike[][]): void;
getAvoidPolygons(): LngLat[][];
clearAvoidPolygons(): void;
setAvoidRoad(value: string): void;
getAvoidRoad(): string;
clearAvoidRoad(): void;
constructor(client: Client, options?: {
map?: Map;
policy?: 'TIME' | 'DISTANCE';
});
setPolicy(policy: 'TIME' | 'DISTANCE'): void;
search(origin: LngLatLike, destination: LngLatLike, optionsOrCallback?: {
waypoints?: LngLatLike[];
} | ServiceCallback<DrivingResult>, callback?: ServiceCallback<DrivingResult>): Promise<{
info: string;
start: LngLat;
end: LngLat;
routes: Route[];
}>;
clear(): void;
destroy(): void;
}
export declare class Walking extends Driving {
}
export interface LocationResult extends Partial<AddressFields> {
position: LngLat;
accuracy: number;
speed: number | null;
heading: number | null;
timestamp: number;
}
export interface LocationOptions extends PositionOptions {
needAddress?: boolean;
}
export declare class Geolocation extends Evented {
constructor(options?: LocationOptions, addresses?: LocationAddressSession | undefined, transformPosition?: (p: LngLat) => LngLat);
getCurrentPosition(callback?: Callback<LocationResult>): Promise<LocationResult>;
watchPosition(callback: Callback<LocationResult>): number;
clearWatch(id: number): void;
cancel(): void;
destroy(): void;
}
geocoder
import { Client, ServiceCallback, LngLat, LngLatLike } from './core';
import { Service } from './services';
export interface GeocoderOptions {
radius?: number;
extensions?: 'base' | 'all';
lang?: 'zh_cn';
batch?: false;
city?: string;
}
export interface AddressComponent {
country: string;
countryCode: string;
province: string;
city: string;
citycode: string;
district: string;
adcode: string;
township: string;
towncode: string;
street: string;
streetNumber: string;
building: string;
neighborhood: string;
}
export interface RegeocodeFeature {
id: string;
name: string;
kind: string;
type: string;
distance: number;
direction: string;
location: LngLat;
}
export interface Regeocode {
formattedAddress: string;
addressComponent: AddressComponent;
pois: RegeocodeFeature[];
roads: RegeocodeFeature[];
location: LngLat;
matched: boolean;
matchType: 'inside' | 'nearby' | 'none';
addressSource: string;
distance: number | null;
}
export interface RegeocodeResult {
info: string;
regeocode: Regeocode;
datasetVersion: string;
coordinateSystem: 'WGS84' | 'GCJ02';
}
export interface GeocodeResult {
info: string;
geocodes: {
formattedAddress: string;
location: LngLat;
level: string;
id: string;
addressSource: string;
}[];
datasetVersion: string;
coordinateSystem: 'WGS84' | 'GCJ02';
}
/** Reverse geocoding over the authorized published roads, places and public buildings. */
export declare class Geocoder extends Service {
constructor(client: Client, options?: GeocoderOptions);
getLocation(address: string, callback?: ServiceCallback<GeocodeResult>): Promise<GeocodeResult>;
getAddress(location: LngLatLike, callback?: ServiceCallback<RegeocodeResult>): Promise<RegeocodeResult>;
}
compat-geolocation
import { LngLat, Pixel } from './core';
import { Control, ControlOptions, Map } from './map';
import { LocationResult } from './services';
import type { CompatCallback } from './amap-compat';
import { LocationAddressSession } from './location-address';
export interface CompatGeolocationOptions extends PositionOptions, ControlOptions {
buttonPosition?: ControlOptions['position'];
buttonOffset?: Pixel | [number, number];
showButton?: boolean;
showMarker?: boolean;
showCircle?: boolean;
panToLocation?: boolean;
zoomToAccuracy?: boolean;
convert?: false;
needAddress?: boolean;
}
/** Browser measurements and optional map UI. Never creates an IP-based or synthetic fix. */
export declare class CompatGeolocation extends Control {
constructor(options?: CompatGeolocationOptions, addresses?: LocationAddressSession, transformPosition?: (p: LngLat) => LngLat);
setMap(map: Map | null): this;
getCurrentPosition(callback?: CompatCallback<LocationResult>): Promise<LocationResult>;
watchPosition(callback?: CompatCallback<LocationResult>): number;
clearWatch(id: number): void;
cancel(): void;
destroy(): void;
}
location-address
import { LngLat, SDKError } from './core';
import type { AddressComponent, RegeocodeResult } from './geocoder';
export interface AddressFields {
formattedAddress: string;
addressStatus: 'pending' | 'complete' | 'no_data' | 'error';
addressComponent?: AddressComponent;
addressError?: SDKError;
}
interface AddressService {
getAddress(point: LngLat): Promise<RegeocodeResult>;
cancel(): void;
destroy(): void;
}
/** Per-location-owner, in-memory only. No address lookup can delay a location measurement. */
export declare class LocationAddressSession {
constructor(service: AddressService, now?: () => number);
snapshot(position: LngLat): AddressFields;
request(position: LngLat, callback: (fields: AddressFields) => void): void;
cancel(): void;
destroy(): void;
}
export {};