最新js获取经纬度并计算两个位置之间的距离

ios10 获取经纬度有两种方法javascript

    1.在iOS 10中,苹果对webkit定位权限进行了修改,全部定位请求的页面必须是https协议的java

    2.引用库ios

    下面用百度库web

<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=6yAoynmTPNlTBa8z1X4LfwGE&services=&t=20170309210149"></script>api

 

            function getLocation()
            {
                var geolocation = new BMap.Geolocation();
                geolocation.getCurrentPosition(function (r) {
                    if (this.getStatus() == BMAP_STATUS_SUCCESS)
                    {
                        document.getElementById("wd").value = r.point.lat;
                        document.getElementById("jd").value = r.point.lng;
                    }
                });
            }函数

 

            function showPosition()
            {
                 var lat1 = 32.0893;        //第一点纬度
                 var lng1 = 118.9443;    //第一点经度
                
                var lat2 = 32.0393;        //第二点纬度
                var lng2 = 118.8443;    //第二点经度
                
                var radLat1 = rad(lat1);
                var radLat2 = rad(lat2);
                
                var a = radLat1 - radLat2;
                var b = rad(lng1) - rad(lng2);
                var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
                Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
                s = s *6378.137 ;
                s = Math.round(s * 10000) / 10000; //输出为千米
            }this

         
            function rad(d)
            {
                return d * Math.PI / 180.0;//经纬度转换成三角函数中度分表形式。
            }ip