china-location

JS Library for 中国行政区划信息
Simplify the usage of chinese administrative division data.
An React Component For this
Usage
npm install china-location --save
or
yarn add china-location
import list from 'china-location/dist/location.json';
import ChinaLocation from 'china-location';
const location = new ChinaLocation(list);
const defaultLocation = location.getCurrentAddress();
const newProvince = '320000';
const newCity = '320500';
const newDistrict = '320509';
location.changeProvince(newProvince);
location.changeCity(newCity);
location.changeDistrict(newDistrict);
location.changeLocation(newProvince, newCity, newDistrict);
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 in your project, you can:
import yourNewLocation from 'path/to/location.json';
import ChinaLocation from 'china-location';
const location = new ChinaLocation(yourNewLocation);
LICENSE
MIT