Skip to content

🇨🇳JS Library for Chinese Administrative Division. 中国行政区划信息-区划代码数据库(GB/T 2260)

License

Notifications You must be signed in to change notification settings

qingjiaowochengzd/china-location

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

china-location

npm Building Status

NPM module for 中国行政区划信息
Simplify the use of chinese administrative division data.

An React Component For this

Usage

npm install china-location --save or yarn add china-location

const list = require('china-location/dist/location.json');
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), and clone this repo and:

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:

const yourNewLocation = require('path/to/location.json');
const ChinaLocation = require('china-location');
const location = new ChinaLocation(yourNewLocation);
//...

LICENSE

MIT

About

🇨🇳JS Library for Chinese Administrative Division. 中国行政区划信息-区划代码数据库(GB/T 2260)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%