Skip to content

服务插件

@gmap/services 提供地图服务 API 封装。

安装

bash
npm install @gmap/services

服务列表

地理编码 Geocoding

ts
import { Geocoding } from "@gmap/services";

// 地址 → 坐标
const result = await Geocoding.geocode("北京市天安门", {
  provider: "amap",
  key: "your-key",
});
// { lng: 116.397, lat: 39.908, address: '...' }

// 坐标 → 地址
const reverse = await Geocoding.regeocode([116.397, 39.908], {
  provider: "amap",
  key: "your-key",
});

POI 搜索

ts
import { POISearch } from "@gmap/services";

const results = await POISearch.search("餐厅", {
  provider: "amap",
  key: "your-key",
  center: [116.397, 39.908],
  radius: 1000,
  limit: 10,
});

路径规划 Routing

ts
import { Routing } from "@gmap/services";

const route = await Routing.driving(
  [116.397, 39.908], // 起点
  [121.474, 31.23], // 终点
  { provider: "amap", key: "your-key" },
);
// { distance: 1200000, duration: 43200, steps: [...] }

// 其他模式
await Routing.walking(from, to, opts);
await Routing.transit(from, to, opts);
await Routing.riding(from, to, opts);

天气 Weather

ts
import { Weather } from "@gmap/services";

const live = await Weather.live("北京", { provider: "amap", key: "your-key" });
// { temperature: 25, weather: '晴', humidity: 40, ... }

const forecast = await Weather.forecast("北京", {
  provider: "amap",
  key: "your-key",
  days: 3,
});

自动补全 Autocomplete

ts
import { Autocomplete } from "@gmap/services";

const suggestions = await Autocomplete.suggest("天安", {
  provider: "amap",
  key: "your-key",
  center: [116.397, 39.908],
});

行政区 District

ts
import { District } from "@gmap/services";

const result = await District.search("朝阳区", {
  provider: "amap",
  key: "your-key",
  subdistrict: 2,
});

交通 Traffic

ts
import { Traffic } from "@gmap/services";

const status = await Traffic.getStatus([116, 39, 117, 40], {
  provider: "amap",
  key: "your-key",
});

IP 定位 IPPosition

ts
import { IPPosition } from "@gmap/services";

const location = await IPPosition.locate({ provider: "amap", key: "your-key" });
// { ip: '...', city: '北京', lng: 116.397, lat: 39.908 }

支持的提供商

服务本平台高德百度天地图
地理编码
POI
路径规划
天气
自动补全
行政区
交通
IP 定位

最后更新:

四川省交通运输综合地理服务平台 地图开发框架