Silent 6 years ago
parent
commit
fbf3244546
1 changed files with 21 additions and 23 deletions
  1. 21 23
      resources/views/admin/base/locations/index.blade.php

+ 21 - 23
resources/views/admin/base/locations/index.blade.php

xqd
@@ -70,34 +70,32 @@ $(function() {
     $('#my-location-btn').on('click', function () {
         console.log(navigator.geolocation);
         if (navigator.geolocation) {
-            navigator.geolocation.getCurrentPosition(sgShowPosition);
+            navigator.geolocation.getCurrentPosition(function (position) {
+                console.log(position);
+                var lat = position.coords.latitude;
+                var lng = position.coords.longitude;
+                console.log(lat, lng);
+                //调用地图命名空间中的转换接口   type的可选值为 1:GPS经纬度,2:搜狗经纬度,3:百度经纬度,4:mapbar经纬度,5:google经纬度,6:搜狗墨卡托
+                qq.maps.convertor.translate(new qq.maps.LatLng(lat, lng), 1, function(res){
+                    //取出经纬度并且赋值
+                    var latlng = res[0];
+                    console.log(latlng);
+                    var map = new qq.maps.Map(document.getElementById("container"), {
+                        center:  latlng,
+                        zoom: 13
+                    });
+                    //设置marker标记
+                    var marker = new qq.maps.Marker({
+                        map : map,
+                        position : latlng
+                    });
+                });
+            });
         }
         else {
             alert('浏览器不支持定位')
 		}
     });
-
-    function sgShowPosition(position)
-    {
-        var lat = position.coords.latitude;
-        var lng = position.coords.longitude;
-        console.log(lat, lng);
-		//调用地图命名空间中的转换接口   type的可选值为 1:GPS经纬度,2:搜狗经纬度,3:百度经纬度,4:mapbar经纬度,5:google经纬度,6:搜狗墨卡托
-        qq.maps.convertor.translate(new qq.maps.LatLng(lat, lng), 1, function(res){
-            //取出经纬度并且赋值
-            var latlng = res[0];
-			console.log(latlng);
-            var map = new qq.maps.Map(document.getElementById("container"), {
-                center:  latlng,
-                zoom: 13
-            });
-            //设置marker标记
-            var marker = new qq.maps.Marker({
-                map : map,
-                position : latlng
-            });
-        });
-    }
 });
 </script>
 @endsection