Esempio n. 1
0
        private void InitLocationClient()
        {
            _LocaltionClient = new AMapLocationClient(ApplicationContext);
            _LocaltionClient.SetLocationListener(new MapLocaltionListenerImp(OnLocationChanged));

            //创建定位设置
            var option = new AMapLocationClientOption();

            //设置定位间隔,单位毫秒,默认为2000ms,最低1000ms。
            option.SetInterval(15 * 1000);
            //单位是毫秒,默认30000毫秒,建议超时时间不要低于8000毫秒。
            option.SetHttpTimeOut(10 * 1000);
            //关闭缓存机制
            option.SetLocationCacheEnable(false);
            if (null != _LocaltionClient)
            {
                _LocaltionClient.SetLocationOption(option);
                _LocaltionClient.StopLocation();
                _LocaltionClient.StartLocation();
            }
        }
Esempio n. 2
0
        private void InitLocation()
        {
            //声明mlocationClient对象

            LocationClient = new AMapLocationClient(this);
            //初始化定位参数
            AMapLocationClientOption mLocationOption = new AMapLocationClientOption();

            //设置定位监听
            LocationClient.SetLocationListener(new LocationListener(this));
            //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
            mLocationOption.SetLocationMode(AMapLocationClientOption.AMapLocationMode.HightAccuracy);
            //设置定位间隔,单位毫秒,默认为2000ms
            mLocationOption.SetInterval(2000);
            //设置定位参数
            LocationClient.SetLocationOption(mLocationOption);
            // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗,
            // 注意设置合适的定位时间的间隔(最小间隔支持为1000ms),并且在合适时间调用stopLocation()方法来取消定位请求
            // 在定位结束后,在合适的生命周期调用onDestroy()方法
            // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除
            //启动定位
            LocationClient.StartLocation();
        }