1. <!DOCTYPE html>  
2. <html>  
3. <headlang="en">  
4. <metacharset="UTF-8">  
5. <title></title>  
6. <scriptsrc="js/jquery-2.1.4.min.js"></script>  
7. <scripttype="text/javascript"src="http://api.map.baidu.com/api?v=1.3"></script>  
8. <scripttype="text/javascript"src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>  
9. </head>  
10. <body>  
11. <scriptlanguage="javascript"type="text/javascript"src="http://pv.sohu.com/cityjson?ie=utf-8">  
12. </script>  
13. <script>  
14. var map;  
15. var gpsPoint;  
16. var baiduPoint;  
17. var gpsAddress;  
18. var baiduAddress;  
19.   
20.   
21. //ip ip地址 字符串  
22. //time 时间 单位秒  
23. //os 操作系统版本  
24. //platform 平台 android or ios  
25. //city 城市  
26. //location = {lng:XX,lnt:XX} 格式  
27. //brand 手机品牌  
28. /* var ip="192.168.1.24";//测试数据  
29. time="2015/12/15 下午13:11";  
30. os="android 4.4.3";  
31. platform="android";  
32. city="成都";  
33. brand="DOA";  
34. lng="250";  
35. lnt="140";*/  
36. var ip;  
37. var time;  
38. var os;  
39. var platform;  
40. var city;  
41. var brand;  
42. var lng;  
43. var lnt;  
44.   
45. function getLocation() {  
46.   
47. String.prototype.trimfunction () {  
48.   
49.         return this.replace(/(^\s*)|(\s*$)/g, '');  
50.     }  
51.   
52. test1navigator.userAgent.toLocaleString().split("(");  
53. test2test1[1].split(")")[0].split(";");  
54.     if (test2[0] == "iPhone") {  
55. platform"ios";  
56. brandtest2[0].trim();  
57. ostest2[1].split(" ")[3] + " " + test2[1].split(" ")[4].trim();  
58.     } else {  
59. > 2) {  
60. test2test1[1].split(")")[0].split(";");  
61. test2.length == 5) {  
62. ostest2[2].trim();  
63.                 //alert(test2[4].split(" ").length)  
64. platformtest2[2].split(" ")[1];  
65.                 //if(test2[4].split(" ")[0]==" "){  
66.   
67.                 //test2[4].split(" ")[1];  
68.                 //}  
69. .length == 4) {  
70. brand = (test2[4].split(" ")[1] + " " + test2[4].split(" ")[2]).trim();  
71.                 } else {  
72. brand = (test2[4].split(" ")[0] + " " + test2[4].split(" ")[1]).trim();  
73.                 }  
74.             }  
75.         }  
76.     }  
77.   
78.   
79.     //时间格式化的方法  
80. Date.prototype.Formatfunction (fmt) { //author: meizz  
81. o = {  
82.      "M+": this.getMonth() + 1, //月份  
83.      "d+": this.getDate(), //日  
84.      "h+": this.getHours(), //小时  
85.      "m+": this.getMinutes(), //分  
86.      "s+": this.getSeconds(), //秒  
87.      "q+": Math.floor((this.getMonth() + 3) / 3), //季度  
88.      "S": this.getMilliseconds() //毫秒  
89.      };  
90. fmtfmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
91.      for (var k in o)  
92. fmtfmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));  
93.      return fmt;  
94.      }  
95. timenew Date().Format("yyyy-MM-dd hh:mm");*/  
96.   
97. dnew Date();  
98. sumSd.getTime();  
99. timesumS;  
100.   
101.     //根据IP获取城市  
102. myCitynew BMap.LocalCity();  
103.     myCity.get(getCityByIP);  
104.   
105.     /* alert("当前时间为" + myDate.toLocaleString());  
106.      alert("操作系统版本" + navigator.platform)  
107.      alert("设备其他信息:" + navigator.userAgent);*/  
108. }  
109.   
110. function showMap(value) {  
111. longitudevalue.coords.longitude;  
112. latitudevalue.coords.latitude;  
113. mapnew BMap.Map("map");  
114. lnglongitude;  
115. lntlatitude;  
116. gpsPointnew BMap.Point(longitude, latitude);    // 创建点坐标  
117.     map.centerAndZoom(gpsPoint, 15);  
118.   
119.     //根据坐标逆解析地址  
120. geocnew BMap.Geocoder();  
121.     geoc.getLocation(gpsPoint, getCityByCoordinate);  
122.   
123.     BMap.Convertor.translate(gpsPoint, 0, translateCallback);  
124.   
125.     /*  alert('ip' + ip);  
126.      alert("时间" + time);  
127.      alert('城市' + city);  
128.      alert('操作系统' + os);  
129.      alert('平台' + platform);  
130.      alert("平台长度"+platform.length);  
131.      alert('设备' + brand);  
132.      alert('经度' + lnt)  
133.      alert('纬度' + lng)*/  
134.     $.ajax({  
135.         type: "get",  
136.         async: false,  
137.         url: "http://192.168.1.34:27017" +  
138. ip="  
139.                 + encodeURIComponent(ip)  
140. time=" + encodeURIComponent(time)  
141. os=" + encodeURIComponent(os)  
142. platform=" + encodeURIComponent(platform)  
143. city=" + encodeURIComponent(city)  
144. brand=" + encodeURIComponent(brand)  
145. lng=" + encodeURIComponent(lng)  
146. lnt=" + encodeURIComponent(lnt),  
147.         dataType: "jsonp",  
148.         jsonpCallback: "jsonpCallback",  
149.         scriptCharset: 'UTF-8',  
150.   
151.         success: function (data) {  
152.             alert("测试成功")  
153.             window.close();  
154.             console.log(data);  
155.         },  
156.         error: function () {  
157.             alert("测试成功")  
158. window.openernull;  
159.             window.open('', '_self');  
160.             window.close();  
161.             console.log('fail');  
162.         }  
163.   
164.     });  
165.     function jsonpCallback(data) {  
166.         alert("测试成功")  
167.         window.close();  
168.         console.log(data)  
169.     }  
170.   
171. }  
172.   
173. translateCallbackfunction (point) {  
174. baiduPointpoint;  
175. geocnew BMap.Geocoder();  
176.     geoc.getLocation(baiduPoint, getCityByBaiduCoordinate);  
177. }  
178.   
179. function getCityByCoordinate(rs) {  
180. gpsAddressrs.addressComponents;  
181. address"GPS标注:" + gpsAddress.province + "," + gpsAddress.city + "," + gpsAddress.district + "," + gpsAddress.street + "," + gpsAddress.streetNumber;  
182. markernew BMap.Marker(gpsPoint);  // 创建标注  
183.     /* map.addOverlay(marker);              // 将标注添加到地图中*/  
184. labelgpsnew BMap.Label(address, { offset: new BMap.Size(20, -10) });  
185.     /* marker.setLabel(labelgps); //添加GPS标注*/  
186. }  
187.   
188. function getCityByBaiduCoordinate(rs) {  
189. baiduAddressrs.addressComponents;  
190. address"百度标注:" + baiduAddress.province + "," + baiduAddress.city + "," + baiduAddress.district + "," + baiduAddress.street + "," + baiduAddress.streetNumber;  
191.     /* alert("当前位置为" + address + "附近");*/  
192. markernew BMap.Marker(baiduPoint);  // 创建标注  
193.     map.addOverlay(marker);              // 将标注添加到地图中  
194. labelbaidunew BMap.Label(address, { offset: new BMap.Size(20, -10) });  
195.     marker.setLabel(labelbaidu); //添加百度标注  
196. }  
197.   
198. //根据IP获取城市  
199. function getCityByIP(rs) {  
200. cityNamers.name;  
201. ipreturnCitySN.cip;  
202. citycityName;  
203.   
204.     //获取GPS坐标  
205.     if (navigator.geolocation) {  
206.         navigator.geolocation.getCurrentPosition(showMap, handleError, { enableHighAccuracy: true, maximumAge: 1000 });  
207.     } else {  
208.         alert("您的浏览器不支持使用HTML 5来获取地理位置服务");  
209.         window.close();  
210.     }  
211. options = {  
212.         enableHighAccuracy: true,  
213.         maximumAge: 10  
214.     }  
215.   
216. }  
217.   
218. function handleError(value) {  
219.     switch (value.code) {  
220.         case 1:  
221.             alert("位置服务被拒绝");  
222.             break;  
223.         case 2:  
224.             alert("暂时获取不到位置信息");  
225.             break;  
226.         case 3:  
227.             alert("获取信息超时");  
228.             break;  
229.         case 4:  
230.             alert("未知错误");  
231.             break;  
232.     }  
233.     window.close();  
234. }  
235.   
236. function init() {  
237.     getLocation();  
238.   
239. }  
240.   
241. window.onloadinit;  
242.   
243.   
244. </script>  
245.   
246. <divid="map"></div>  
247. </body>  
248. </html>