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

js获取手机信息的更多相关文章

  1. 前端通过js获取手机型号

    ###前段通过js获取手机型号 需求: 用户登录后记录当前的手机型号并记录 插件: mobile-detect.js插件地址 mobile-device-js插件地址 使用步骤: 获取UA信息-> ...

  2. 微信小程序开发(六)获取手机信息

    // succ.js var app = getApp() Page({ data: { mobileModel: '', // 手机型号 mobileePixelRatio: '', // 手机像素 ...

  3. JS获取手机型号和系统

    废话不多说,直接上源码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&q ...

  4. js get browser vertion (js获取浏览器信息版本)

    1问题:js get browser vertion (js获取浏览器信息版本) 2解决方案 Copy this script into your JavaScript files. It works ...

  5. iOS 整理笔记 获取手机信息(UIDevice、NSBundle、NSLocale)

    /*    iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发ap ...

  6. 【风马一族_Android】Android 从命令行界面获取手机信息

    Android 从命令行界面获取手机信息 1: cmd 打开命令行界面 2:adb devices   获取与电脑相连的设备,例如:模拟器.真机(手机) (右击“标记”,选择设备名称,点击“Ctrl+ ...

  7. Android 获取手机信息,设置权限,申请权限,查询联系人,获取手机定位信息

    Android 获取手机信息,设置权限,申请权限,查询联系人,获取手机定位信息 本文目录: 获取手机信息 设置权限 申请权限 查询联系人 获取手机定位信息 调用高德地图,设置显示2个坐标点的位置,以及 ...

  8. android 获取手机信息工具类

    package com.yqy.yqy_listviewheadview; import android.content.Context; import android.telephony.Telep ...

  9. android获取手机信息大全

    IMEI号,IESI号,手机型号: private void getInfo() { TelephonyManager mTm = (TelephonyManager) getSystemServic ...

随机推荐

  1. 实战Google深度学习框架-C3-TensorFlow入门

    第三章:TensorFlow入门 TensorFlow存在计算模型,数据模型和运算模型(本文用TF代表TensorFlow) 3.1 计算模型-计算图 3.1.1 计算图的概念 TensorFlow这 ...

  2. Pandas系列(十三)-其他常用功能

    一.统计数据频率 1. values_counts pd.value_counts(df.column_name) df.column_name.value_counts() Series.value ...

  3. EF CodeFirst系列(9)---添加初始化数据和数据库迁移策略

    1.添加初始化数据(Seed) 我们可以在初始化数据库的过程中给数据库添加一些数据.为了实现初始化数据(seed data)我们必须创建一个自定义的数据库初始化器(DB initializer),并重 ...

  4. [再寄小读者之数学篇](2014-10-18 利用 Lagrange 中值定理求极限)

    试求 $$\bex \vlm{n}n^2\sex{x^\frac{1}{n}-x^\frac{1}{n+1}},\quad x>0. \eex$$ 解答: $$\beex \bea \mbox{ ...

  5. Javaweb学习笔记——(二十七)——————泛型、泛型的通配符、反射泛型信息、反射注解、注解

    泛型     1.泛型类:具有一个或多个类型变量的类,称之为泛型类 class A<T>{ } 2.在创建泛型实例时,需要为其类型变量赋值 A<String> a = new ...

  6. 获取搜索结果的真实URL、描述、标题

    1.场景 爬虫练手代码 2.代码 Python2: #!/usr/bin/python # -*- coding:utf-8 -*- import requests from lxml import ...

  7. Illegal invocation with document.querySelector [duplicate]

    document.querySelectorAll赋给其它变量时, 为什么要.bind(document)? https://stackoverflow.com/questions/12637061/ ...

  8. C“控制”Lua

    [前言] 写过Windows程序的人都知道,对于应用程序,如果需要在本地保存一些配置信息,我们经常将这些配置信息写在注册表或者本地的配置文件中,很多应用都是将一些配置信息写在配置文件中,比如以ini结 ...

  9. shim和polyfill

    shim是将新的api引入旧的环境 polyfill是一段代码或插件 https://www.aliyun.com/jiaocheng/773254.html 理解得不够透彻...

  10. Java_Number(装箱和拆箱)

    所有的包装类(Integer.Long.Byte.Double.Float.Short)都是抽象类Number子类 装箱: 自动将基本数据类型装换为包装器类型 拆箱: 自动将包装器类型转换为基本数据类 ...