11# China Zipcode Adcode Data
22
3- 本项目包含中国省市区县的 Adcode 和 Zipcode 对应数据。
4- 数据来源于网络整理。
3+ [ ![ License: MIT ] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
4+ [ ![ NPM Version ] ( https://img.shields.io/npm/v/@tombcato/china-zipcode-data.svg )] ( https://www.npmjs.com/package/@tombcato/china-zipcode-data )
55
6- ## 如何使用 (jsDelivr CDN)
76
8- 你可以直接通过 CDN 引用本数据,无需自行部署服务器。
7+ 本项目包含中国省市区县的 ** 行政编码(Adcode)** 和 ** 邮政编码(Zipcode)** 对应数据。
8+ 可与高德地图/百度地图/腾讯地图等地图数据进行关联,实现地址解析后通过Adcode获取地址邮编的功能。
99
10- ### 获取最新版本
11- ``` javascript
12- // 建议使用具体版本号,例如 @1.0.0,避免缓存问题
13- const url = " https://cdn.jsdelivr.net/gh/tombcato/china-zipcode-data@main/china_zipcode_adcode.json" ;
14-
15- fetch (url)
16- .then (response => response .json ())
17- .then (data => {
18- console .log (data);
19- // 在此处处理数据
20- });
21- ```
10+ 可通过使用 [ ** 整理好的JSON元数据** ] ( ./china_zipcode_adcode.json ) 或者 ** JS SDK** 两种方式使用。
2211
23- ### 模糊查询示例
24- ``` javascript
25- async function search (keyword ) {
26- const response = await fetch (" https://cdn.jsdelivr.net/gh/tombcato/china-zipcode-data@main/china_zipcode_adcode.json" );
27- const data = await response .json ();
28- return data .filter (item =>
29- item .name .includes (keyword) ||
30- item .province .includes (keyword) ||
31- item .city .includes (keyword)
32- );
33- }
34- ```
35-
36- ## 数据字段说明
12+ 数据来源于网络整理,并进行了一定的清洗和整理。参考:
13+ [ 2023年中华人民共和国县以上行政区划代码] ( https://www.mca.gov.cn/mzsj/xzqh/2023/202301xzqh.html )
14+ [ 高德全国邮政编码查询] ( https://ditu.amap.com/postcode/ )
15+
16+ 感谢开源项目提供部分数据:
17+ [ China-zip-code-latitude-and-longitude] ( https://github.com/sfyc23/China-zip-code-latitude-and-longitude )
18+ [ Administrative-divisions-of-China] ( https://github.com/modood/Administrative-divisions-of-China )
3719
3820## JavaScript SDK 使用指南
3921
4022本项目提供了一个同构的 JavaScript SDK,支持 Node.js 和浏览器环境。
4123
4224### 安装
4325``` bash
44- npm install china-zipcode-adcode
26+ npm install @tombcato/ china-zipcode-data
4527```
4628
4729### 使用 (Node.js / Webpack / ESM)
4830``` javascript
49- import { get , search } from ' china-zipcode-adcode ' ;
31+ import { get , search } from ' @tombcato/ china-zipcode-data ' ;
5032
51- // 1. 精确查找
33+ // 1. 通过adcode精确查找
5234const region = await get (' 110101' );
5335console .log (region);
5436
@@ -63,11 +45,15 @@ const res2 = await search('朝阳', '北京');
6345const res3 = await search (' 朝阳' , null , ' 吉林' );
6446```
6547
66- ### 使用 (浏览器 CDN)
48+ ### 使用 (浏览器 CDN 推荐 )
6749无需安装,直接引用即可。数据会自动从 jsDelivr CDN 加载。
50+
51+ > ** 提示** : ` @latest ` 会指向最新版本,但可能有缓存延迟。生产环境建议锁定版本号 (如 ` @1.0.2 ` )。
52+
6853``` html
6954<script type =" module" >
70- import { search } from ' https://cdn.jsdelivr.net/gh/<你的GitHub用户名>/<仓库名>@main/src/index.js' ;
55+ // 引用最新版 (使用 +esm 自动处理模块加载)
56+ import { search } from ' https://cdn.jsdelivr.net/npm/@tombcato/china-zipcode-data@latest/+esm' ;
7157
7258 search (' 朝阳' ).then (results => {
7359 console .log (results);
@@ -78,6 +64,7 @@ const res3 = await search('朝阳', null, '吉林');
7864---
7965
8066## 字段说明
67+ - ` code ` : 行政编码
8168- ` name ` : 名称
8269- ` province ` : 省份
8370- ` city ` : 城市
@@ -94,7 +81,7 @@ import requests
9481import json
9582
9683# 方式 1: 在线加载
97- url = " https://cdn.jsdelivr.net/gh/<你的GitHub用户名>/<仓库名>@main /china_zipcode_adcode.json"
84+ url = " https://cdn.jsdelivr.net/gh/tombcato/china-zipcode-data@latest /china_zipcode_adcode.json"
9885data = requests.get(url).json()
9986
10087# 方式 2: 本地加载
0 commit comments