- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta charset="UTF-8">
- <title></title>
- <script src="js/jquery-2.1.4.min.js"></script>
- <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
- <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
- </head>
- <body>
- <script language="javascript" type="text/javascript" src="http://pv.sohu.com/cityjson?ie=utf-8">
- </script>
- <script>
- var map;
- var gpsPoint;
- var baiduPoint;
- var gpsAddress;
- var baiduAddress;
- //ip ip地址 字符串
- //time 时间 单位秒
- //os 操作系统版本
- //platform 平台 android or ios
- //city 城市
- //location = {lng:XX,lnt:XX} 格式
- //brand 手机品牌
- /* var ip="192.168.1.24";//测试数据
- var time="2015/12/15 下午13:11";
- var os="android 4.4.3";
- var platform="android";
- var city="成都";
- var brand="DOA";
- var lng="250";
- var lnt="140";*/
- var ip;
- var time;
- var os;
- var platform;
- var city;
- var brand;
- var lng;
- var lnt;
- function getLocation() {
- String.prototype.trim = function () {
- return this.replace(/(^\s*)|(\s*$)/g, ‘‘);
- }
- var test1 = navigator.userAgent.toLocaleString().split("(");
- var test2 = test1[1].split(")")[0].split(";");
- if (test2[0] == "iPhone") {
- platform = "ios";
- brand = test2[0].trim();
- os = test2[1].split(" ")[3] + " " + test2[1].split(" ")[4].trim();
- } else {
- if (test1.length > 2) {
- var test2 = test1[1].split(")")[0].split(";");
- if (test2.length == 5) {
- os = test2[2].trim();
- //alert(test2[4].split(" ").length)
- platform = test2[2].split(" ")[1];
- //if(test2[4].split(" ")[0]==" "){
- //test2[4].split(" ")[1];
- //}
- if (test2[4].split(" ").length == 4) {
- brand = (test2[4].split(" ")[1] + " " + test2[4].split(" ")[2]).trim();
- } else {
- brand = (test2[4].split(" ")[0] + " " + test2[4].split(" ")[1]).trim();
- }
- }
- }
- }
- //时间格式化的方法
- /* Date.prototype.Format = function (fmt) { //author: meizz
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
- time = new Date().Format("yyyy-MM-dd hh:mm");*/
- var d = new Date();
- var sumS = d.getTime();
- time = sumS;
- //根据IP获取城市
- var myCity = new BMap.LocalCity();
- myCity.get(getCityByIP);
- /* alert("当前时间为" + myDate.toLocaleString());
- alert("操作系统版本" + navigator.platform)
- alert("设备其他信息:" + navigator.userAgent);*/
- }
- function showMap(value) {
- var longitude = value.coords.longitude;
- var latitude = value.coords.latitude;
- map = new BMap.Map("map");
- lng = longitude;
- lnt = latitude;
- gpsPoint = new BMap.Point(longitude, latitude); // 创建点坐标
- map.centerAndZoom(gpsPoint, 15);
- //根据坐标逆解析地址
- var geoc = new BMap.Geocoder();
- geoc.getLocation(gpsPoint, getCityByCoordinate);
- BMap.Convertor.translate(gpsPoint, 0, translateCallback);
- /* alert(‘ip‘ + ip);
- alert("时间" + time);
- alert(‘城市‘ + city);
- alert(‘操作系统‘ + os);
- alert(‘平台‘ + platform);
- alert("平台长度"+platform.length);
- alert(‘设备‘ + brand);
- alert(‘经度‘ + lnt)
- alert(‘纬度‘ + lng)*/
- $.ajax({
- type: "get",
- async: false,
- url: "http://192.168.1.34:27017" +
- "?ip="
- + encodeURIComponent(ip)
- + "&time=" + encodeURIComponent(time)
- + "&os=" + encodeURIComponent(os)
- + "&platform=" + encodeURIComponent(platform)
- + "&city=" + encodeURIComponent(city)
- + "&brand=" + encodeURIComponent(brand)
- + "&lng=" + encodeURIComponent(lng)
- + "&lnt=" + encodeURIComponent(lnt),
- dataType: "jsonp",
- jsonpCallback: "jsonpCallback",
- scriptCharset: ‘UTF-8‘,
- success: function (data) {
- alert("测试成功")
- window.close();
- console.log(data);
- },
- error: function () {
- alert("测试成功")
- window.opener = null;
- window.open(‘‘, ‘_self‘);
- window.close();
- console.log(‘fail‘);
- }
- });
- function jsonpCallback(data) {
- alert("测试成功")
- window.close();
- console.log(data)
- }
- }
- translateCallback = function (point) {
- baiduPoint = point;
- var geoc = new BMap.Geocoder();
- geoc.getLocation(baiduPoint, getCityByBaiduCoordinate);
- }
- function getCityByCoordinate(rs) {
- gpsAddress = rs.addressComponents;
- var address = "GPS标注:" + gpsAddress.province + "," + gpsAddress.city + "," + gpsAddress.district + "," + gpsAddress.street + "," + gpsAddress.streetNumber;
- var marker = new BMap.Marker(gpsPoint); // 创建标注
- /* map.addOverlay(marker); // 将标注添加到地图中*/
- var labelgps = new BMap.Label(address, { offset: new BMap.Size(20, -10) });
- /* marker.setLabel(labelgps); //添加GPS标注*/
- }
- function getCityByBaiduCoordinate(rs) {
- baiduAddress = rs.addressComponents;
- var address = "百度标注:" + baiduAddress.province + "," + baiduAddress.city + "," + baiduAddress.district + "," + baiduAddress.street + "," + baiduAddress.streetNumber;
- /* alert("当前位置为" + address + "附近");*/
- var marker = new BMap.Marker(baiduPoint); // 创建标注
- map.addOverlay(marker); // 将标注添加到地图中
- var labelbaidu = new BMap.Label(address, { offset: new BMap.Size(20, -10) });
- marker.setLabel(labelbaidu); //添加百度标注
- }
- //根据IP获取城市
- function getCityByIP(rs) {
- var cityName = rs.name;
- ip = returnCitySN.cip;
- city = cityName;
- //获取GPS坐标
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(showMap, handleError, { enableHighAccuracy: true, maximumAge: 1000 });
- } else {
- alert("您的浏览器不支持使用HTML 5来获取地理位置服务");
- window.close();
- }
- var options = {
- enableHighAccuracy: true,
- maximumAge: 10
- }
- }
- function handleError(value) {
- switch (value.code) {
- case 1:
- alert("位置服务被拒绝");
- break;
- case 2:
- alert("暂时获取不到位置信息");
- break;
- case 3:
- alert("获取信息超时");
- break;
- case 4:
- alert("未知错误");
- break;
- }
- window.close();
- }
- function init() {
- getLocation();
- }
- window.onload = init;
- </script>
- <div id="map"></div>
- </body>
- </html>
时间: 2024-11-07 18:36:07