1 Star 0 Fork 4

Hypocrite / js-citys

forked from Devin / js-citys 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

js-citys

项目介绍

中国城市数据,支持省市区查询,支持浏览器、Node.js 环境

中国省市区数据调用示例

1. 导入js文件
<script type="text/javascript" src="dist/full-citys.js"></script>



const DC = require('./dist/node/full-citys.js');

2. 相关api

//获取省份列表
var provs = DC.getProvs();  //=> [{ id: 17, name: "湖北" }, ...]

//获取城市列表
var citys = DC.getCitys(prov_id);   //=> [{ id: 0, code: "CN101200101", name: "武汉" }, ...]

//获取区域列表
var areas = DC.getAreas(prov_id, city_id);   //=> [{ id: 11, code: "CN101200113", name: "洪山" }, ...]

//获取省份对象
var data_prov = DC.getAuto(prov_id);  //=> { id: 17, name: "湖北" }

//获取城市对象
var data_city = DC.getAuto(prov_id, city_id);  //=> { pid: 17, id: 0, code: "CN101200101", name: "武汉" }

//获取区域对象
var data_area = DC.getAuto(prov_id, city_id, area_id);  //=> { pid: 17, cid: 0, id: 11, code: "CN101200113", name: "洪山" }

//格式化省市区对象
var data_prov = DC.formatData(data_prov);  //=> { type: 2, pid: 17, prov: "湖北"}
var data_city = DC.formatData(data_city);  //=> { type: 3, pid: 17, prov: "湖北", cid: 0, city: "武汉", code: "CN101200101"}
var data_area = DC.formatData(data_area);  //=> { type: 4, pid: 17, prov: "湖北", cid: 0, city: "武汉", aid: 11, area: "洪山", code: "CN101200113"}

var Types = DC.Types;
data_prov.type == Types.prov;  //=>  true
data_city.type == Types.city;  //=>  true
data_area.type == Types.area;  //=>  true

//根据城市或区域代码获取对象
var data_city = DC.getCityOrArea("CN101200101");  //=> { type: 3, pid: 17, prov: "湖北", cid: 0, city: "武汉", code: "CN101200101"}
var data_area = DC.getCityOrArea("CN101200113");  //=> { type: 4, pid: 17, prov: "湖北", cid: 0, city: "武汉", aid: 11, area: "洪山", code: "CN101200113"}

//查找省份对象,支持模糊查找
DC.find("湖北省");
DC.find("湖北");
DC.find("湖北电信");

//=>  { type: 2, pid: 17, prov: "湖北"}

//查找城市对象,支持模糊查找
DC.find("湖北省武汉市");
DC.find("湖北武汉电信");
DC.find("湖北武汉");
DC.find("武汉");

//=>  { type: 3, pid: 17, prov: "湖北", cid: 0, city: "武汉", code: "CN101200101"}

//查找区域对象,支持模糊查找
DC.find("湖北省武汉市洪山区");
DC.find("湖北武汉洪山电信");
DC.find("湖北武汉洪山");
DC.find("武汉市洪山区");
DC.find("武汉洪山电信");
DC.find("武汉洪山");
DC.find("洪山");

//=>  { type: 4, pid: 17, prov: "湖北", cid: 0, city: "武汉", aid: 11, area: "洪山", code: "CN101200113"}

//查找省市区对象,精确查找
DC.findData("湖北");  //=>  { type: 2, pid: 17, prov: "湖北"}
DC.findData("湖北", "武汉");  //=>  { type: 3, pid: 17, prov: "湖北", cid: 0, city: "武汉", code: "CN101200101"}
DC.findData("湖北", "武汉", "洪山");  //=>  { type: 4, pid: 17, prov: "湖北", cid: 0, city: "武汉", aid: 11, area: "洪山", code: "CN101200113"}
The MIT License (MIT) Copyright (c) 2018 Devin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

中国城市数据,支持省市区查询,支持浏览器、Node.js 环境 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/zqc925/js-citys.git
git@gitee.com:zqc925/js-citys.git
zqc925
js-citys
js-citys
master

搜索帮助