最近用到地址信息,查到JSON数据, 就是还要自己转化去处理,于是写了简单的node模块方便使用,目前只支持到省市区,街道暂不支持,后序会更新。
用法
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();
Forked GITHUB
Simple React Component For this