# hotCity 城市选择器, 城市数据库可自己导出
##后台数据API 由HotApp小程序统计提供并维护,如果需要导出并部署在公司的生产环境,最后有SQL导出下载地址
## 使用方法
- 复制pages/district到你的项目目录
- 把样式文件district.wxss引入到您调用本插件的作用域
`@import "你的路径/district/wxParse.wxss";`
- 在需要使用的模版的x.wxml中引入模版文件wxParse.wxml
```javascript
<import src="../district/district.wxml"/>
<template is="district" data="{{districts}}" />
```
- 在对应的js中引入district.js文件
`var WxParse = require('你的路径/district/district.js');`
- 使用:
在你的js文件中, 必须要绑定四个事件:
getProvinces、getCities、getDistricts和finish
其中
getProvinces事件需要调用districts.getProvinces(this);
getCities事件需要调用districts.getCities(this, event);
getDistricts事件需要调用districts.getDistricts(this, event);
finish事件需要调用districts.finish(this, event);
## 应用截图
![首页](https://github.com/hotapp888/hotcity/blob/master/screenshots/1.png)
###样式一 通过导航实现三级选择
![首页](https://github.com/hotapp888/hotcity/blob/master/screenshots/2.png)
![首页](https://github.com/hotapp888/hotcity/blob/master/screenshots/3.png)
![首页](https://github.com/hotapp888/hotcity/blob/master/screenshots/4.png)
###样式二 三级联动
![首页](https://github.com/hotapp888/hotcity/blob/master/screenshots/5.png)
![首页](https://github.com/hotapp888/hotcity/blob/master/screenshots/6.png)
![首页](https://github.com/hotapp888/hotcity/blob/master/screenshots/7.png)
## 统计截图 通过接入hotApp的统计,可知道大家喜欢那个城市选择器
![首页](https://github.com/hotapp888/hotcity/blob/master/screenshots/01.png)
## 数据来源
数据来源于高德地图, 从高德地图的行政区划查询中找到了api请求地址, 然后再写脚本把高德所有的数据全部导入到hotapp的数据库中
## 数据库表设计
高德地图返回的数据格式是:
```json
{
adcode: "220100"
center: "125.3245,43.886841"
citycode: "0431"
districts: []
level: "city"
name: "长春市"
}
```
我稍微改造了一下, 数据库字段设计为:
```sql
CREATE TABLE `tbl_districts` (
`adcode` char(6) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`lng` decimal(12,8) unsigned NOT NULL,
`lat` decimal(12,8) unsigned NOT NULL,
`level` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`parent_adcode` char(6) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`adcode`),
KEY `tbl_districts_parent_adcode_index` (`parent_adcode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
```
其中, lng表示经度, lat表示纬度, level有"province"、"city"和"district"三种类型
## 接口使用方法
一共就一个接口: `GET /districts`, 如果不带参数, 表示获取的是所有province级别的数据, 如果带上参数parent_adcode, 表示获取指定的parent_adcode的数据.
比如: 要获取所有province级别的数据: `GET https://wxapi.hotapp.cn/api/districts` , 返回格式为:
```json
[
{
"adcode": 110000,
"name": "北京市",
"lng": "116.40528500",
"lat": "39.90498900",
"level": "province",
"parent_adcode": ""
},
{
"adcode": 120000,
"name": "天津市",
"lng": "117.19018200",
"lat": "39.12559600",
"level": "province",
"parent_adcode": ""
},
...
{
"adcode": 420000,
"name": "湖北省",
"lng": "114.29857200",
"lat": "30.58435500",
"level": "province",
"parent_adcode": ""
},
...
]
```
然后如果需要获取湖北省所有的city, 那么调用`GET https://wxapi.hotapp.cn/api/districts?parent_adcode=420000`, 返回格式为:
```json
[
{
"adcode": 420100,
"name": "武汉市",
"lng": "114.29857200",
"lat": "30.58435500",
"level": "city",
"parent_adcode": "420000"
},
{
"adcode": 420700,
"name": "鄂州市",
"lng": "114.89059300",
"lat": "30.39653600",
"level": "city",
"parent_adcode": "420000"
},
{
"adcode": 420800,
"name": "荆门市",
"lng": "112.20425100",
"lat": "31.03542000",
"level": "city",
"parent_adcode": "420000"
},
...
]
```
然后想要再获取武汉市所有的区, 那么就调用`GET https://wxapi.hotapp.cn/api/districts?parent_adcode=420100`, 返回格式为:
```json
[
{
"adcode": 420102,
"name": "江岸区",
"lng": "114.30304000",
"lat": "30.59491100",
"level": "district",
"parent_adcode": "420100"
},
{
"adcode": 420103,
"name": "江汉区",
"lng": "114.28310900",
"lat": "30.57877100",
"level": "district",
"parent_adcode": "420100"
},
...
]
```
另外, 考虑到有些用户可能以后会自己开发后台, 所以也提供了数据库导出接口, 在这里 http://wenda.hotapp.cn/article/3, 这个会导出我们的数据库表接口和所有数据!
--------
hot云笔记小程序 云端存储记事的开源小程序
https://github.com/hotapp888/hotapp-notepad
没有合适的资源?快使用搜索试试~ 我知道了~
200个微信小程序案例源码可运行.zip
共2000个文件
png:1882个
js:1399个
wxss:1013个
5星 · 超过95%的资源 需积分: 48 366 下载量 67 浏览量
2020-06-09
23:28:48
上传
评论 45
收藏 311.07MB ZIP 举报
温馨提示
HotApp云笔记-精品开源demo基于免费API HotCity城市选择器开源-城市数据库可自己导出 V2EX社区:获取最新文章,最热文章,所有节点;适用1122 福利demo:妹子图:分类标签,根据分类标签获取分类图片 基于微信小程序开发的仿微信demo 精品demo推荐:爱拼宝宝:导航固定在顶部,适用1122版本 精品demo推荐:事项助手;引入兼容库Bluebird支持Promise 使用第三方模块Underscore.js, Immutable.js, UUID 推荐研究demo:豆瓣电影:代码中有大量注释 微信下程序demo:电影麻辣烫 微信小程序模仿拉钩招聘APP源代码 微信小程序24点计算游戏 微信小程序24点计算游戏(2) 微信小程序demo: cnode练习版 微信小程序demo: github博客 微信小程序demo: ihobby 微信小程序demo: jinri, 富文本解析 微信小程序demo: Railay: 整体框架 微信小程序demo: requestURL 的连通性测试 微信小程序demo: SDK.CN 微信小程序demo: titans 微信小程序demo: todo: wx.setStorageSync(KEY,DATA) 方法存放数据 微信小程序demo: V2EX (11月9日版) 微信小程序demo:百思不得姐 微信小程序demo:百思不得姐:使用不得姐api 微信小程序demo:柏拉图测试:趣味图片生成器 微信小程序demo:宝宝起名
资源推荐
资源详情
资源评论
收起资源包目录
200个微信小程序案例源码可运行.zip (2000个子文件)
demo导入说明.docx 182KB
demo导入说明.docx 182KB
demo导入说明.docx 182KB
demo导入说明.docx 182KB
源代码说明.docx 129KB
other.html 2KB
GreetingController.java 810B
Greeting.java 360B
App.java 288B
pinyin.js 698KB
json.js 590KB
av-weapp.js 474KB
addressForm.js 253KB
chance.js 223KB
chance.js 223KB
bluebird.js 204KB
av-weapp-min.js 150KB
immutable.js 139KB
immutable.js 139KB
topic_data.js 137KB
showdown.js 73KB
polyfill.js 73KB
showdown.js 71KB
showdown.js 71KB
showdown.js 71KB
underscore.modified.js 57KB
underscore.modified.js 57KB
bluebird.js 54KB
underscore.js 52KB
underscore.js 52KB
markdown.js 50KB
chengyu.js 33KB
addCur.js 32KB
runtime.js 21KB
list.js 19KB
marked.min.js 19KB
util.js 18KB
index-list.js 18KB
html2json.js 13KB
index.js 13KB
util.js 13KB
createMerchandise.js 12KB
index.js 11KB
utils.js 11KB
gift-result.js 11KB
index.js 11KB
hotapp.js 11KB
hotapp.js 11KB
wxParse.js 10KB
es6.promise.js 10KB
index.js 9KB
reading.js 9KB
createStore.js 9KB
util.js 9KB
es6.symbol.js 9KB
uuid.modified.js 9KB
uuid.modified.js 9KB
service.js 9KB
htmlparser.js 9KB
htmlparser.js 9KB
htmlparser.js 8KB
md5.js 8KB
hunter.js 8KB
uuid.js 8KB
uuid.js 8KB
playground.js 8KB
html2json.js 8KB
server.js 8KB
html2json.js 8KB
app.js 7KB
html2json.js 7KB
index.js 7KB
login.js 7KB
wxDiscode.js 7KB
wx_API.js 7KB
base64.modified.js 7KB
base64.modified.js 7KB
wxDiscode.js 7KB
wxDiscode.js 7KB
count.js 7KB
count.js 7KB
base64.js 7KB
base64.js 7KB
app.js 7KB
example.js 7KB
example.js 7KB
question.js 6KB
wxDiscode.js 6KB
gotogo.js 6KB
index.js 6KB
util.js 6KB
es6-promise.min.js 6KB
create-page.js 6KB
util.js 6KB
util.js 6KB
index.js 6KB
component.js 6KB
combineReducers.js 6KB
index.js 6KB
home.js 6KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- flybirding100112021-08-02非常棒,赞一个
IQcoder
- 粉丝: 225
- 资源: 402
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功