Use Google map to parse the default geographic locations of 4095 provinces, cities, and counties in mainland China and obtain geographic coordinates

Source: Internet
Author: User

1. For the core method, see the next article.

2. Core source code:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> using Google map to analyze the default geographic location of 4095 provinces and cities in mainland China, obtain geographic coordinates </title> <br/> <meta name = "author" content = "Xing, xiudong, xingxiudong@gmail.com 2010.05.28"/> <Br/> <MCE: style> <! -- <Br/> ol {display: block;} <br/> ol Li {width: 600px; float: Left ;}< br/> --> </MCE: style> <style mce_bogus = "1"> ol {display: block ;}< br/> ol Li {width: 600px; float: Left ;} </style> <br/> </pead> <br/> <body> <br/> <p> list being parsed </p> <br/> <Div ID = "going"> </div> <br/> <p> resolution success list (<span id = "succc"> 0 </span>) </p> <br/> <Div id = "output"> </div> <br/> <p> resolution failure list (<span id = "failc"> 0 </span>) </p> <br/> <Div id = "unparse"> </div> <B R/> <p> Update statement </p> <br/> <Div id = "Update"> </div> <br/> <MCE: script Type = "text/JavaScript" src = "http://maps.google.com/maps? File = API & V = 2 "mce_src =" http://maps.google.com/maps? File = API & V = 2 "> </MCE: SCRIPT> <br/> <MCE: Script Type =" text/JavaScript "src =" jquery. JS "mce_src =" jquery. JS "> </MCE: SCRIPT> <br/> <MCE: Script Type =" text/JavaScript "> <! -- <Br/> // <! -- [CDATA [<br/> $ (document ). ready (function () {<br/> var dataarr = baseprovicelib. getdata (); </P> <p> // dataarr. length <br/> for (VAR I = 0; I <dataarr. length; I ++) {<br/> var p_index = dataarr [I] [0]; <br/> var p_name = dataarr [I] [1]; </P> <p> parsestring2glatlng (p_name.replace (// s +/g ,""). replace ("/*/g", ""), p_index, I); <br/>}< br/>}); <br/> var succc = 0; <br/> var failc = 0; <br/> // longitude LNG lat <br/> fun Ction parsestring2glatlng (address, p_index, I) {<br/> // $ ("# going "). append ("Parsing" + p_index + ":" + address + "<br/>"); <br/> var geocoder = new gclientgeocoder (); <br/> If (geocoder) {<br/> geocoder. getlatlng (address, function (point) {<br/> If (! Point) {<br/> $ ("# failc "). text (++ failc); <br/> // $ ("# unparse "). append (I + "resolution failed (" + address ). append (")!, "); <Br/> parsestring2glatlng (address, p_index, I); <br/>}else {<br/> $ (" # succc "). text (++ succc); <br/> $ ("# output "). append (I + "parsed successfully! "+ Address +" -- latitude: "+ point. LAT () + "longitude:" + point. LNG ()). append ("<br/>"); <br/> appendinsertsql (p_index, address, point. LAT (), point. LNG (); <br/>}< br/>}); <br/>}< br/> function appendinsertsql (p_index, p_names, Lat, LNG) {<br/> $ ("# Update "). append ("insert into geo_cn (p_index, p_names, Lat, LNG) values ('" + p_index + "', '" + p_names + "', '"+ lat +"', '"+ LNG + "');"). append ("<br/>"); <br/>}< br/> baseprovicelib ={< br/> getdata: function () {<br/> return [<br/> // ===================== province ======== ==========< br/> ["110000 ", "Beijing"], <br/> ["120000", "Tianjin"], <br/> ["130000", "Hebei Province"], <br/> ["140000", "Shanxi Province"], <br/> ["150000", "Inner Mongolia Autonomous Region"], <br/> ...... <br/> ...... <br/> ["659004", "wujiaqu city, administrative unit of Xinjiang Uygur Autonomous Region"] <br/>]; <br/>}< br/> }; <br/> //] --> <br/> // --> </MCE: SCRIPT> <br/> </body> <br/> </ptml> <br/> 

Result:

0 resolution successful! Beijing -- latitude: 39.904667 longitude: 116.408198
1 Resolution successful! Tianjin -- latitude: 39.120876
Longitude: 117.21503
2 Resolution successful! Hebei -- latitude: 38.037252 longitude: 114.469259
3 Resolution successful! Shanxi --
Latitude: 37.873464 longitude: 112.562537
4 Resolution successful! Inner Mongolia -- latitude: 40.823542 longitude: 111.674121
5
Resolution successful! Liaoning -- latitude: 41.836521 longitude: 123.437162
6 Resolution successful! Jilin Province -- latitude: 43.896289
Longitude: 125.325766
7 Resolution successful! Heilongjiang -- latitude: 45.742352 longitude: 126.66268
8 Resolution successful! Shanghai --
Latitude: 31.230708 longitude: 121.472916
9 Resolution successful! Jiangsu -- latitude: 32.061241 longitude: 118.762313
10
Resolution successful! Zhejiang -- latitude: 30.266214 longitude: 120.15383
11 Resolution successful! Anhui -- latitude: 31.860611
Longitude: 117.2847
12 Resolution successful! Fujian -- latitude: 26.101062 longitude: 119.295863
13 Resolution successful! Jiangxi --
Latitude: 28.674628 longitude: 115.90893
14 Resolution successful! Shandong -- latitude: 36.669227 longitude: 117.019896
15
Resolution successful! Henan -- latitude: 34.767884 longitude: 113.687816
17 Resolution successful! Hunan -- latitude: 28.113053
Longitude: 112.983521
18 Resolution successful! Guangdong -- latitude: 23.131614 longitude: 113.266558
20 Resolution successful! Hainan --
Latitude: 20.029341 longitude: 110.356808
19 Resolution successful! Guangxi Zhuang Autonomous Region -- latitude: 22.815547
Longitude: 108.327697
22 Resolution successful! Sichuan -- latitude: 30.650892 longitude: 104.076418
24 Resolution successful! Yunnan --
Latitude: 25.045254 longitude: 102.709809
25 Resolution successful! Tibet Autonomous Region -- latitude: 29.647951 longitude: 91.117006
27
Resolution successful! Gansu -- latitude: 36.0593 longitude: 103.826363
30 resolution successful! Xinjiang Uygur Autonomous Region -- latitude: 43.793147
Longitude: 87.627546
32 Resolution successful! Hong Kong Special Administrative Region -- latitude: 22.396428 longitude: 114.109497
34 resolution successful!
Xinjiang Construction Corps -- latitude: 43.947639 longitude: 81.336729
36 resolution successful! Beijing city -- latitude: 39.904667
Longitude: 116.408198
37 Resolution successful! Tianjin Municipal District -- latitude: 39.120876 longitude: 117.21503
38 resolution successful! Tianjin City
-- Latitude: 38.925744 longitude: 116.923253
44 Resolution successful! Baoding City, Hebei Province -- latitude: 38.873972
Longitude: 115.46463
45 resolution successful! Zhangjiakou City, Hebei Province -- latitude: 40.767576 longitude: 114.885951
43 resolution successful!
Xingtai City, Hebei Province -- latitude: 37.070589 longitude: 114.504874
51 resolution successful! Datong City, Shanxi Province -- latitude: 40.076816
Longitude: 113.300126
52 resolution successful! Yangquan City, Shanxi Province -- latitude: 37.856658 longitude: 113.580415
54 resolution successful!
Shanxi Jincheng -- latitude: 35.49087 longitude: 112.851768
55 Resolution successful! Shuozhou City, Shanxi Province -- latitude: 39.331149
Longitude: 112.432714
59 resolution successful! Linfen city, Shanxi Province -- latitude: 36.087743 longitude: 111.51885

..................

 

Download complete source code (including 4095 provinces, cities, and counties): Click to download

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.