Hotcity Small Program City selector, city database can be exported by itself

Source: Internet
Author: User

Hotcity City Selector, the city database can export its own background data API is provided and maintained by the Hotapp applet statistics, if it is necessary to export and deploy in the company's production environment, finally SQL export

Open Source Address https://github.com/hotapp888/hotcity

How to use
    • Copy Pages/district to your project directory

    • Introduce the style file District.wxss to the scope where you call the plugin@import "你的路径/district/wxParse.wxss";

    • Introduce a template file in the x.wxml of the template you need to use Wxparse.wxml

<import src=". /district/district.wxml"/><template is=" District"Data=" {{districts}}/ >          
    • Introducing the District.js file in the corresponding JSvar WxParse = require(‘你的路径/district/district.js‘);

    • Use: In your JS file, you must bind four events:
      Getprovinces, GetCities, getdistricts and finish
      which
      Getprovinces event needs to call Districts.getprovinces (this);
      The GetCities event needs to call Districts.getcities (this, event);
      The Getdistricts event needs to call Districts.getdistricts (this, event);
      The finish event needs to call Districts.finish (this, event);

Application

Style one three-level selection by navigation

Style two or three-level linkage

Statistics by accessing Hotapp statistics, you know people like that city selector

Data sources

Data from the gold map, from the administrative divisions of the German map to find the API request address, and then write a script to import all the data into the Hotapp database

database table Design

The data format returned by the German map is:

{    "220100"    "125.3245,43.886841" 0431"City" Changchun "}  

I changed a little bit. The database field is designed to:

CREATETABLE 'Tbl_districts ' (' Adcode`Char6) COLLATE Utf8_unicode_ciNot NULL,' Name`varchar) COLLATE Utf8_unicode_ciNot NULL,' LNG`Decimal12,8) unsignedNot NULL,' Lat`Decimal12,8) unsignedNot NULL,' Level`varcharTen) COLLATE Utf8_unicode_ciNot NULL,' Parent_adcode`Char6) COLLATE utf8_unicode_ci not NULL,   ' Created_at ' timestamp NULL DEFAULT null,  ' Updated_at timestamp null DEFAULT null, PRIMARY KEY ( Span class= "pl-s" > "Adcode", KEY  " ( Parent_adcode)) Engine=innodb DEFAULT charset=utf8 collate=utf8_unicode_ ci;                 

Among them, LNG represents longitude, lat represents latitude, level has "province", "City" and "district" three kinds

How to use the interface

A total of one interface: GET /districts If the parameter is not taken, it means that all province levels of data are obtained, and if the parameter parent_adcode is taken, the data for the specified Parent_adcode is obtained.

For example: To get all province levels of data: GET https://wxapi.hotapp.cn/api/districts , the return format is:

[  {"Adcode":110000,"Name":"Beijing","LNG":"116.40528500",The LAT":"39.90498900",The level":"Province","Parent_adcode":"" }, {"Adcode":120000,"Name":"Tianjin","LNG":"117.19018200",The LAT":"39.12559600",The level":"Province","Parent_adcode":"" },... {"Adcode":420000,  "Name":  "Hubei " 114.29857200 " "Lat":  "Level":  "Province" "  "},                

Then if you need to get all the city of Hubei province, then call GET https://wxapi.hotapp.cn/api/districts?parent_adcode=420000 , return format is:

[  {"Adcode":420100,"Name":"Wuhan","LNG":"114.29857200",The LAT":"30.58435500",The level":"City","Parent_adcode":"420000" }, {"Adcode":420700,"Name":"Ezhou","LNG":"114.89059300",The LAT":"30.39653600",The level":"City","Parent_adcode":"420000" }, {"Adcode":420800,  "Name":  "Jingmen " " 112.20425100 " "Lat":  "Level":  "City"  Parent_ Adcode" 420000 "},  ...]                 

And then want to get all the districts in Wuhan, then call GET https://wxapi.hotapp.cn/api/districts?parent_adcode=420100 , return the format as:

[  {"Adcode":420102,"Name":"Jiang ' an","LNG":"114.30304000",The LAT":"30.59491100",The level":"District","Parent_adcode":"420100" }, {"Adcode":420103,  "Name":  "Jianghan District " " 114.28310900 " "Lat":  "Level":  "District" " 420100 "}, Span class= "Pl-ii" ...]                

In addition, given that some users may later develop their own background, so also provides a database export interface, here HTTP://WENDA.HOTAPP.CN/ARTICLE/3, this will export our database table interface and all the data!

Hot Cloud Note Applet Cloud storage notes Open Source applet Https://github.com/hotapp888/hotapp-notepad

Hotcity Small Program City selector, city database can be exported by itself

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.