https://github.com/jasonboy/china-location
🇨🇳JS Library for Chinese Administrative Division. 中国行政区划信息-区划代码数据库(GB/T 2260)
https://github.com/jasonboy/china-location
Last synced: about 1 year ago
JSON representation
🇨🇳JS Library for Chinese Administrative Division. 中国行政区划信息-区划代码数据库(GB/T 2260)
- Host: GitHub
- URL: https://github.com/jasonboy/china-location
- Owner: JasonBoy
- License: mit
- Created: 2017-09-26T06:16:33.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T19:09:09.000Z (over 3 years ago)
- Last Synced: 2025-03-29T06:08:18.748Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 2.52 MB
- Stars: 90
- Watchers: 5
- Forks: 177
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# china-location
[](https://www.npmjs.com/package/china-location)
[](https://travis-ci.org/JasonBoy/china-location)
JS Library for [中国行政区划信息](https://github.com/mumuy/data_location#中国行政区划信息)
Simplify the usage of chinese administrative division data.
[An React Component](https://github.com/JasonBoy/react-china-location) For this
## Usage
`npm install china-location --save` or
`yarn add china-location`
```javascript
import list from 'china-location/dist/location.json';
import ChinaLocation from 'china-location';
//const ChinaLocation = require('china-location');
const location = new ChinaLocation(list);
//get default location
//{
// province: {code: '110000', name: '北京市'},
// city: {code: '110000', name: '北京市'},
// district: {code: '110101', name: '东城区'}
//}
const defaultLocation = location.getCurrentAddress();
//change location
const newProvince = '320000';
const newCity = '320500';
const newDistrict = '320509';
//use select html tag to change different part
location.changeProvince(newProvince);
location.changeCity(newCity);
location.changeDistrict(newDistrict);
//or you can change location at one time
location.changeLocation(newProvince, newCity, newDistrict);
//{
// province: {code: '320000', name: '江苏省'},
// city: {code: '320500', name: '苏州市'},
// district: {code: '320509', name: '吴江区'}
//}
const newLocation = location.getCurrentAddress();
```
## Build your own location.json
In case the package is not packed with the latest location data, get/clone the data from [mumuy/data_location(list.json)](https://github.com/mumuy/data_location),
and clone this repo and:
```bash
git clone git@github.com:JasonBoy/china-location.git
cd china-location
npm run reformat -- /path/to/data_location/list.json
# and the location(.min).json will be output to ./dist dir
```
And in your project, you can:
```javascript
import yourNewLocation from 'path/to/location.json';
import ChinaLocation from 'china-location';
const location = new ChinaLocation(yourNewLocation);
//...
```
## LICENSE
MIT