Quellcode durchsuchen

新增定位功能

qihanjiao vor 7 Jahren
Ursprung
Commit
4b30246e70
1 geänderte Dateien mit 46 neuen und 6 gelöschten Zeilen
  1. 46 6
      wateroPF-wechat-web/src/main/webapp/view/add_machine.html

+ 46 - 6
wateroPF-wechat-web/src/main/webapp/view/add_machine.html

@@ -6,11 +6,11 @@
 		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
 		<meta name="apple-mobile-web-app-capable" content="yes">
 		<meta name="apple-mobile-web-app-status-bar-style" content="black">
-		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/css/mui.min.css?v=2017072401" />
-		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/css/mui.picker.min.css?v=2017072401" />
-		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/new/css/iconfont.css?v=2017072401" />
-		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/css/style.css?v=2017072401" />
-		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/new/css/personal_information.css?v=2017072401" />
+		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/css/mui.min.css?v=2017092601" />
+		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/css/mui.picker.min.css?v=2017092601" />
+		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/new/css/iconfont.css?v=2017092601" />
+		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/css/style.css?v=2017092601" />
+		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/wateroPF/new/css/personal_information.css?v=2017092601" />
 		<style>
 			h4{margin-top:5px;margin-bottom: 5px;font-size: 20px;}
 			.btn-pull-code{position: absolute;right: 10px;top:7px;height:34px;padding:0 6px;border-radius: 5px; line-height: 34px;font-size: 12px; color: #fff; background: #24cae9;}
@@ -63,6 +63,7 @@
 					<div></div>
 				</div>
 				<div class="mui-content-padded">
+					<div><span class="iconfont icon-dingwei" style="color: #f00;"></span>地址:<span id="wx-ads"></span></div>
 				<form class="mui-input-group">
 					<div class="mui-input-row">
 						<label>您的姓名</label>
@@ -133,9 +134,48 @@
                 //return false;
             });
         }, false);
+
+
 		document.querySelector('.loading-bg').style.display='none';
 	});
-
+window.onload=function(){
+    wx.getLocation({
+        type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
+        success: function (res) {
+            var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
+            var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
+            var speed = res.speed; // 速度,以米/每秒计
+            var accuracy = res.accuracy; // 位置精度
+            getLocation(latitude,longitude);
+        },
+        cancel: function (res) {
+            mui.alert('用户拒绝授权获取地理位置');
+        }
+    });
+};
+function getLocation(latitude,longitude){
+    $.ajax({
+        type: 'get',
+        url: 'http://apis.map.qq.com/ws/geocoder/v1/',
+        data:{
+            "location" : latitude+","+longitude,
+			"coord_type":1,
+			"key":'NDABZ-4NBR6-EC2SH-MUIX3-CDL6E-IJB7C',
+			"get_poi":0
+        },
+        dataType: 'json',
+        timeout: 15000,
+        success: function(dt) {
+            console.log(dt);
+            if(dt.status==0){
+                $("#wx-ads").text(dt.result.ad_info.province+"-"+dt.result.ad_info.city+"-"+dt.result.ad_info.district);
+			}
+        },
+        error: function(xhr, type, errorThrown) {
+            console.log("请检查网络或刷新页面重试!");
+        }
+    });
+}
 	mui('body').on('tap', '#btn_submit', function() {
 		change_input();
 		if(check){