# @medmotion-open/tdt-node

> 简化天地图web服务的使用,ts类型提示

Latest version **1.0.0** (published 2023-11-27) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @medmotion-open/tdt-node
pnpm add @medmotion-open/tdt-node
yarn add @medmotion-open/tdt-node
bun add @medmotion-open/tdt-node
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-11-27 |
| First published | 2023-11-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | medmotion_zc |
| Maintainers | medmotion_zc |
| Keywords | 天地图api |

## Links

- npm: https://www.npmjs.com/package/@medmotion-open/tdt-node
- npm.io page: https://npm.io/package/@medmotion-open/tdt-node

## Recent versions

- 1.0.0 (latest) — 2023-11-27

## README

# 简化 天地图的 web 服务 API 的使用

node 环境需要设置 httpAdapter

小程序和浏览器使用见 https://www.npmjs.com/package/@medmotion-open/tdt

# 支持的接口

[❌]地名搜索 V2.0 (开发中) 类型定义部分支持

[❌]公交规划 (开发中)

[✅]地理编码接口

[❌]逆地理编码查询 (开发中)

[❌]行政区划服务 (开发中)

[❌]驾车规划 (开发中)

[❌]静态地图 API (开发中)

[❌]地图 API (开发中)

[❌]网页 API (开发中)

# 代理

```js
const T_MAP = require('@medmotion-open/tdt-node');

const axios = require('axios'); // 也可以用别的

const map = new T_MAP(key, {
  proxy: 'http://api.tianditu.gov.cn', // 换成你自己的
});
```

# 网络适配器 - node 环境必须

可以用自己的网络请求方法体

但是返回结果需要自己处理

# 用法

```js
const T_MAP = require('@medmotion-open/tdt-node');

const axios = require('axios'); // 也可以用别的

try {
  const map = new T_MAP(key, {
    httpAdapter: axios.get,
  });

  const res = await map.gencode({
    keyWord: '北京市延庆区延庆镇莲花池村前街50夕阳红养老院',
  });
  console.log(res);

  // 或

  const res = map
    .gencode({
      keyWord: '北京市延庆区延庆镇莲花池村前街50夕阳红养老院',
    })
    .then((res) => {
      console.log(res);
    });
} catch (error) {
  console.error(error);
}
```

# 刚刚打算做个简化的使用

也是第一次尝试写个 ts 类型定义的插件包

可能比较慢，但可以自己引用 baseReques 来使用

用法如下

如官方示例为 http://api.tianditu.gov.cn/geocoder?ds={"keyWord":"北京市延庆区延庆镇莲花池村前街50夕阳红养老院"}&tk=您的密钥

```ts
const T_MAP = require('@medmotion-open/tdt-node');

const axios = require('axios'); // 也可以用别的

const map = new T_MAP(key, {
  httpAdapter: axios.get,
});
const ds = JSON.stringify({
  keyWord: '北京市延庆区延庆镇莲花池村前街50夕阳红养老院',
}); // 自己处理参数
map.baseRequest({
  url: 'geocoder',
  params: {
    ds,
  },
});

interface GenCodeReq {
  location: {
    /**
     * 检索时的keyWord
     */
    keyWord: string;
    /**
     * 坐标点显示经度
     */
    lon: string;
    /**
     * 坐标点显示纬度
     */
    lat: string;
    /**
     * 类别名称
     */
    level?: string;
    /**
     * 附近相似点  开启周边查询必需返回。
     */
    typeRound?: string;
  };
}

map.baseRequest<GenCodeReq>({
  url: 'geocoder',
  params: {
    ds,
  },
});
```

---
_Source: https://npm.io/package/@medmotion-open/tdt-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
