在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ 高德地圖定位JS API不準(zhǔn)確問(wèn)題

高德地圖定位JS API不準(zhǔn)確問(wèn)題

  1. 相同位置我使用官方demo定位比較準(zhǔn)確

這個(gè)是移動(dòng)端官方demo 定位

  1. 我把代碼down下來(lái),或者按照官方的教程來(lái),就會(huì)出現(xiàn)偏差,偏差還比較大,如何解決
mapObj = new AMap.Map('iCenter');
mapObj.plugin('AMap.Geolocation', function () {
    geolocation = new AMap.Geolocation({
        enableHighAccuracy: true,//是否使用高精度定位,默認(rèn):true
        timeout: 10000,          //超過(guò)10秒后停止定位,默認(rèn):無(wú)窮大
        maximumAge: 0,           //定位結(jié)果緩存0毫秒,默認(rèn):0
        convert: true,           //自動(dòng)偏移坐標(biāo),偏移后的坐標(biāo)為高德坐標(biāo),默認(rèn):true
        showButton: true,        //顯示定位按鈕,默認(rèn):true
        buttonPosition: 'LB',    //定位按鈕停靠位置,默認(rèn):'LB',左下角
        buttonOffset: new AMap.Pixel(10, 20),//定位按鈕與設(shè)置的??课恢玫钠屏浚J(rèn):Pixel(10, 20)
        showMarker: true,        //定位成功后在定位到的位置顯示點(diǎn)標(biāo)記,默認(rèn):true
        showCircle: true,        //定位成功后用圓圈表示定位精度范圍,默認(rèn):true
        panToLocation: true,     //定位成功后將定位到的位置作為地圖中心點(diǎn),默認(rèn):true
        zoomToAccuracy:true      //定位成功后調(diào)整地圖視野范圍使定位位置及精度范圍視野內(nèi)可見(jiàn),默認(rèn):false
    });
    mapObj.addControl(geolocation);
    geolocation.getCurrentPosition();
    AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
    AMap.event.addListener(geolocation, 'error', onError);      //返回定位出錯(cuò)信息
});

[官方定位教程](http://lbs.amap.com/api/javas...

查到網(wǎng)上說(shuō)要糾偏之類(lèi)的,和這個(gè)有關(guān)系么/?如果要糾偏怎么做?

回答
編輯回答
心夠野

到網(wǎng)上找了個(gè)解決高德偏移量的代碼 https://blog.csdn.net/woshimu...
我的是ip定位 轉(zhuǎn)換過(guò)的定位就準(zhǔn)確了

this.map.plugin('AMap.Geolocation', function () {
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true, //是否使用高精度定位,默認(rèn):true
                timeout: 10000, //超過(guò)10秒后停止定位,默認(rèn):無(wú)窮大
                maximumAge: 0, //定位結(jié)果緩存0毫秒,默認(rèn):0
                showButton: true, //顯示定位按鈕,默認(rèn):true
                buttonPosition: 'LB', //定位按鈕停靠位置,默認(rèn):'LB',左下角
                buttonOffset: new AMap.Pixel(10, 20), //定位按鈕與設(shè)置的停靠位置的偏移量,默認(rèn):Pixel(10, 20)
                showMarker: true, //定位成功后在定位到的位置顯示點(diǎn)標(biāo)記,默認(rèn):true
                panToLocation: true, //定位成功后將定位到的位置作為地圖中心點(diǎn),默認(rèn):true
                zoomToAccuracy: true, //定位成功后調(diào)整地圖視野范圍使定位位置及精度范圍視野內(nèi)可見(jiàn),默認(rèn):false
            });
            _this.map.addControl(geolocation);
            geolocation.getCurrentPosition();
            AMap.event.addListener(geolocation, 'complete', function (data) {
                var gpsPoint = GPS.gcj_encrypt(data.position.getLat(), data.position.getLng());
                _this.centerPointer = gpsPoint;
                _this.circleArea(gpsPoint);
                _this.getAddress(gpsPoint);
            });
            AMap.event.addListener(geolocation, 'error', function () {
                alert('定位失敗');
            });
        });
var GPS = {
            PI: 3.14159265358979324,
            x_pi: 3.14159265358979324 * 3000.0 / 180.0,
            delta: function (lat, lon) {
                var a = 6378245.0; //  a: 衛(wèi)星橢球坐標(biāo)投影到平面地圖坐標(biāo)系的投影因子。
                var ee = 0.00669342162296594323; //  ee: 橢球的偏心率。
                var dLat = this.transformLat(lon - 105.0, lat - 35.0);
                var dLon = this.transformLon(lon - 105.0, lat - 35.0);
                var radLat = lat / 180.0 * this.PI;
                var magic = Math.sin(radLat);
                magic = 1 - ee * magic * magic;
                var sqrtMagic = Math.sqrt(magic);
                dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI);
                dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
                return {
                    'lat': dLat,
                    'lon': dLon
                };
            },
            //WGS-84 to GCJ-02
            gcj_encrypt: function (wgsLat, wgsLon) {
                if (this.outOfChina(wgsLat, wgsLon))
                    return {
                        'lat': wgsLat,
                        'lon': wgsLon
                    };

                var d = this.delta(wgsLat, wgsLon);
                return {
                    'lat': wgsLat + d.lat,
                    'lon': wgsLon + d.lon
                };
            },
            outOfChina: function (lat, lon) {
                if (lon < 72.004 || lon > 137.8347)
                    return true;
                if (lat < 0.8293 || lat > 55.8271)
                    return true;
                return false;
            },
            transformLat: function (x, y) {
                var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
                ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
                ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
                ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
                return ret;
            },
            transformLon: function (x, y) {
                var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
                ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
                ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0;
                ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0;
                return ret;
            }
        };
2018年9月7日 14:37
編輯回答
卟乖

把自動(dòng)偏移改為false

2018年2月27日 07:19