微信定位和HTML5定位

微信定位wx.getLocation

wx.getLocation({ //微信定位
    type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
    success: function (res) {
        var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
        var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
        var locations = longitude + "," + latitude;
        localStorage.setItem("locationCodeVal", locations);
        var data = { // 我的传参
            latLng: locations,
            refNo: logininf.deviceNo,
            orderNo: tfoOrderNo,
            refType: logininf.deviceType
        };
        $.ajax({
            url: tmsUrl + '/save/eqpPositionInfo?token=' + logininf.token, // 我的后端接口
            type: "post",
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function (data) { }
        })
    },
    fail: function () {
        loadData("show", "未能获取地理位置!首先检查手机是否启用微信定位", true)
    }
});

HTML5定位navigator.geolocation

var location_lon = '', location_lat = ''; // 经度,纬度
if (navigator.geolocation) {  //h5定位
    navigator.geolocation.getCurrentPosition(function (position) {
        location_lon = position.coords.longitude; // 经度
        location_lat = position.coords.latitude; // 纬度
        localStorage.setItem("locationCodeVal", location_lon + "," + location_lat);
        getGDPosition(location_lon, location_lat)
    });
} else {
    loadData("show", "您的设备不支持定位功能", true)
}

//将h5经纬度转化为高德经纬度
function getGDPosition(location_lon, location_lat) {
    $.ajax({
        url: "/GDMap-getPoint/assistant/coordinate/convert?locations=" + location_lon + "," + location_lat + "&coordsys=gps&output=json&key=" + mykey,
        type: "get",
        dataType: "json",
        success: function (res) {
            var data = { // 我的传参
                latLng: res.locations,
                refNo: logininf.deviceNo,
                orderNo: tfoOrderNo,
                refType: logininf.deviceType
            };
            $.ajax({
                url: tmsUrl + '/save/eqpPositionInfo?token=' + logininf.token, // 我的后端接口
                type: "post",
                contentType: 'application/json',
                data: JSON.stringify(data),
                success: function (data) { }
            })
        }
    })
}

你可能感兴趣的:(js,js)