Exemplo n.º 1
0
 public void OnReceiveLocation(BDLocation p0)
 {
     if (ReceiveLocation != null)
     {
         ReceiveLocation(p0);
     }
 }
Exemplo n.º 2
0
 public void OnReceivePoi(BDLocation p0)
 {
     if (ReceivePoi != null)
     {
         ReceivePoi(p0);
     }
 }
        void IBDLocationListener.OnReceiveLocation(BDLocation location)
        {
            if (location == null)
            {
                return;
            }
            //Resolver.Resolve<IUserDialogService> ().Alert ("receive dialog");
            MyLocationData locData = new MyLocationData.Builder()
                                     .Accuracy(location.Radius)
                                     // 此处设置开发者获取到的方向信息,顺时针0-360
                                     .Direction(100).Latitude(location.Latitude)
                                     .Longitude(location.Longitude).Build();

            mBaiduMap.SetMyLocationData(locData);
            LatLng cenpt = new LatLng(location.Latitude, location.Longitude);
            //定义地图状态
            MapStatus mMapStatus = new MapStatus.Builder()
                                   .Target(cenpt)
                                   .Zoom(14)
                                   .Build();
            //定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
            //
            MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.NewMapStatus(mMapStatus);

            //改变地图状态
            mBaiduMap.SetMapStatus(mMapStatusUpdate);
        }
        public void OnReceiveLocation(BDLocation location)
        {
            if (stopped)
            {
                return;
            }

            //Debug.WriteLine("LocType: " + location.LocType);
            switch (location.LocType)
            {
            default: break;

            case BDLocation.TypeServerError:
            case BDLocation.TypeNetWorkException:
            case BDLocation.TypeCriteriaException:
                break;

            case BDLocation.TypeGpsLocation:
            case BDLocation.TypeNetWorkLocation:
            case BDLocation.TypeOffLineLocation:
                BMap.MyLocationData loc = new BMap.MyLocationData.Builder()
                                          .Accuracy(location.Radius)
                                          .Direction(location.Direction)
                                          .Latitude(location.Latitude)
                                          .Longitude(location.Longitude)
                                          .Build();
                mapView.Map.SetMyLocationData(loc);

                LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs
                {
                    //Coordinate = new Coordinate(loc.Latitude, loc.Longitude),
                    Direction  = location.Direction,
                    Accuracy   = location.HasRadius ? location.Radius : double.NaN,
                    Altitude   = location.HasAltitude ? location.Altitude : double.NaN,
                    Satellites = location.SatelliteNumber,
                    Type       = location.LocTypeDescription
                });
                return;
            }

            Failed?.Invoke(this, new LocationFailedEventArgs(location.LocType.ToString()));
        }
Exemplo n.º 5
0
        ///// <summary>
        ///// 实现位置监听,实时缓存我的位置
        ///// </summary>
        ///// <param name="location"></param>
        //public void OnReceiveLocation(BDLocation location)
        //{
        //    //在地图上标出我所处的位置
        //    markLocationOnMap(location);
        //    //用于显示我所处位置的详细信息
        //    showMyLocation(location);
        //}


        /// <summary>
        /// 在地图上标出我所处的位置
        /// </summary>
        /// <param name="bdLocation"></param>
        private void markLocationOnMap(BDLocation bdLocation)
        {
            //myLocationLatitude = bdLocation.Latitude;
            //myLocationLongitude = bdLocation.Longitude;
            GeoPoint geoPoint = new GeoPoint((int)(myLocationLatitude * 1E6), (int)(myLocationLongitude * 1E6));

            //GlobalSettings.EventLatitude = (float)myLocationLatitude;
            //GlobalSettings.EventLongitude = (float)myLocationLongitude;

            //mapController.setZoom(16);
            //Bitmap bitmap = BitmapFactory.DecodeResource(GetResources(), R.drawable.point_where);
            //myOverlay = new MyOverlay(null, mapView, bitmap, geoPoint, size);
            //myOverlay.addMyOverlay(myOverlay, bitmap, geoPoint);
            ////mapController.animateTo(geoPoint);

            var pint = new Plugin.Geolocator.Abstractions.Position();

            pint.Latitude  = bdLocation.Latitude;
            pint.Longitude = bdLocation.Longitude;
            Xamarin.Forms.MessagingCenter.Send(pint, "MyBDLocation");
        }
Exemplo n.º 6
0
        public override void OnReceiveLocation(BDLocation lct)
        {
            if (lct == null)
            {
                return;
            }

            try
            {
                var asyncTasker = new AsyncTasker(async() =>
                {
                    try
                    {
                        if (lct != null)
                        {
                            //var msg = $"OnReceiveLocation:{lct.Latitude} Latitude:{lct.Longitude} Address:{lct.Country}{lct.Province}{lct.City}{lct.Address?.Street}";
                            //Android.Util.Log.Info("获取位置:", msg);

                            var _conn = App.Resolve <ILiteDbService <TrackingModel> >();
                            if (_conn != null)
                            {
                                var tracking = new TrackingModel()
                                {
                                    StoreId          = Settings.StoreId,
                                    BusinessUserId   = Settings.UserId,
                                    BusinessUserName = Settings.UserRealName,
                                    Latitude         = lct.Latitude,
                                    Longitude        = lct.Longitude,
                                    CreateDateTime   = DateTime.Now,
                                    Province         = lct.Province,
                                    County           = lct.Country,
                                    City             = lct.City,
                                    Address          = $"{lct.Country}{lct.Province}{lct.City}{lct.Address?.Street}"
                                };

                                //存储本地
                                if (!string.IsNullOrWhiteSpace(tracking.Address))
                                {
                                    var exits = await _conn.Table.CountAsync(s => s.Latitude == lct.Latitude &&
                                                                             s.Longitude == lct.Longitude && s.Address == tracking.Address);
                                    if (exits == 0)
                                    {
                                        await _conn.InsertAsync(tracking);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                });

                asyncTasker?.Execute();
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
Exemplo n.º 7
0
        public override void OnReceiveLocation(BDLocation location)
        {
            #region 官方DEMO 组织信息

            StringBuilder sb = new StringBuilder();
            sb.Append("time : ");
            sb.Append(location.Time);
            sb.Append("\nerror code : ");
            sb.Append(location.LocType);
            sb.Append("\nlatitude : ");
            sb.Append(location.Latitude);
            sb.Append("\nlontitude : ");
            sb.Append(location.Longitude);
            sb.Append("\nradius : ");
            sb.Append(location.Radius);
            if (location.LocType == BDLocation.TypeGpsLocation)
            {                              // GPS定位结果
                sb.Append("\nspeed : ");
                sb.Append(location.Speed); // 单位:公里每小时
                sb.Append("\nsatellite : ");
                sb.Append(location.SatelliteNumber);
                sb.Append("\nheight : ");
                sb.Append(location.Altitude);  // 单位:米
                sb.Append("\ndirection : ");
                sb.Append(location.Direction); // 单位度
                sb.Append("\naddr : ");
                sb.Append(location.AddrStr);
                sb.Append("\ndescribe : ");
                sb.Append("gps定位成功");
            }
            else if (location.LocType == BDLocation.TypeNetWorkLocation)
            {// 网络定位结果
                sb.Append("\naddr : ");
                sb.Append(location.AddrStr);
                //运营商信息
                sb.Append("\noperationers : ");
                sb.Append(location.Operators);
                sb.Append("\ndescribe : ");
                sb.Append("网络定位成功");
            }
            else if (location.LocType == BDLocation.TypeOffLineLocation)
            {// 离线定位结果
                sb.Append("\ndescribe : ");
                sb.Append("离线定位成功,离线定位结果也是有效的");
            }
            else if (location.LocType == BDLocation.TypeServerError)
            {
                sb.Append("\ndescribe : ");
                sb.Append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因");
            }
            else if (location.LocType == BDLocation.TypeNetWorkException)
            {
                sb.Append("\ndescribe : ");
                sb.Append("网络不同导致定位失败,请检查网络是否通畅");
            }
            else if (location.LocType == BDLocation.TypeCriteriaException)
            {
                sb.Append("\ndescribe : ");
                sb.Append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
            }
            sb.Append("\nlocationdescribe : ");
            sb.Append(location.LocationDescribe);// 位置语义化信息
            // System.Collections.Generic.IList list = location.PoiList;// POI数据
            if (location.PoiList != null)
            {
                sb.Append("\npoilist size = : ");
                sb.Append(location.PoiList.Count.ToString());
                foreach (Poi p in location.PoiList)
                {
                    sb.Append("\npoi= : ");
                    sb.Append(p.Id + " " + p.Name + " " + p.Rank);
                }
            }

            // System.Diagnostics.Debug.Write(sb.ToString()); // 调试时请开启注释

            #endregion 官方DEMO 组织信息


            Client.Common.LBSModel r = null;

            #region 判断是否定位错误

            string errorMsg = string.Empty;
            if (location.LocType == BDLocation.TypeServerError)
            {
                errorMsg = "服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因";
            }
            else if (location.LocType == BDLocation.TypeNetWorkException)
            {
                errorMsg = "网络不同导致定位失败,请检查网络是否通畅";
            }
            else if (location.LocType == BDLocation.TypeCriteriaException)
            {
                // errorMsg = "无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机";
                errorMsg = "无法获取有效定位依据导致定位失败,请查看是否开启定位权限(安卓系统请点击【前往系统-位置信息】按钮);若已启用定位权限,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机";
            }

            #endregion

            // 处理定位错误
            if (errorMsg.IsNullOrWhiteSpace() == false)
            {
                r = new Common.LBSModel(errorMsg);
                Client.Common.LBS.OnGetGPSInfo(r);
                return;
            }

            // 4.9E-324 异常情况
            if (location.Longitude.ToString().Contains("E-324") || location.Latitude.ToString().Contains("E-324"))
            {
                errorMsg = $"可能由于正在定位中导致的经纬度信息异常。lng:4.9E-324; lat:4.9E-324";
                r        = new Common.LBSModel(errorMsg);
                Client.Common.LBS.OnGetGPSInfo(r);
                return;
            }

            string tmpGPSInfoType = string.Empty;

            #region 判断定位方式

            if (location.LocType == BDLocation.TypeGpsLocation)
            {
                tmpGPSInfoType = "gps定位成功";
            }
            else if (location.LocType == BDLocation.TypeNetWorkLocation)
            {
                tmpGPSInfoType = "网络定位成功";
            }
            else if (location.LocType == BDLocation.TypeOffLineLocation)
            {
                tmpGPSInfoType = "离线定位成功";
            }

            #endregion

            // 处理定位正常
            r = new Common.LBSModel
                (
                _GPSInfoType: tmpGPSInfoType,
                _Latitude: location.Latitude.ToString(),
                _Longitude: location.Longitude.ToString(),
                _Radius: location.Radius.ToString(),
                _Address: location.AddrStr,
                _LocationDescribe: location.LocationDescribe
                );

            Client.Common.LBS.OnGetGPSInfo(r);
            return;
        }
Exemplo n.º 8
0
        /// <summary>
        /// 用于显示我所处位置的详细信息,不过为了使得界面
        /// 更人性化,这里采用先使得TextView不显示,待用户
        /// 出发相应Menu菜单要求显示时才会显示。
        /// </summary>
        /// <param name="bdLocation"></param>
        private void showMyLocation(BDLocation location)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("time : ");
            sb.Append(location.Time);
            sb.Append("\nerror code : ");
            sb.Append(location.LocType);
            sb.Append("\nlatitude : ");
            sb.Append(location.Latitude);
            sb.Append("\nlontitude : ");
            sb.Append(location.Longitude);
            sb.Append("\nradius : ");
            sb.Append(location.Radius);
            if (location.LocType == BDLocation.TypeGpsLocation)
            {                              // GPS定位结果
                sb.Append("\nspeed : ");
                sb.Append(location.Speed); // 单位:公里每小时
                sb.Append("\nsatellite : ");
                sb.Append(location.SatelliteNumber);
                sb.Append("\nheight : ");
                sb.Append(location.Altitude);  // 单位:米
                sb.Append("\ndirection : ");
                sb.Append(location.Direction); // 单位度
                sb.Append("\naddr : ");
                sb.Append(location.AddrStr);
                sb.Append("\ndescribe : ");
                sb.Append("gps定位成功");
            }
            else if (location.LocType == BDLocation.TypeNetWorkLocation)
            {// 网络定位结果
                sb.Append("\naddr : ");
                sb.Append(location.AddrStr);
                //运营商信息
                sb.Append("\noperationers : ");
                sb.Append(location.Operators);
                sb.Append("\ndescribe : ");
                sb.Append("网络定位成功");
            }
            else if (location.LocType == BDLocation.TypeOffLineLocation)
            {// 离线定位结果
                sb.Append("\ndescribe : ");
                sb.Append("离线定位成功,离线定位结果也是有效的");
            }
            else if (location.LocType == BDLocation.TypeServerError)
            {
                sb.Append("\ndescribe : ");
                sb.Append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因");
            }
            else if (location.LocType == BDLocation.TypeNetWorkException)
            {
                sb.Append("\ndescribe : ");
                sb.Append("网络不同导致定位失败,请检查网络是否通畅");
            }
            else if (location.LocType == BDLocation.TypeCriteriaException)
            {
                sb.Append("\ndescribe : ");
                sb.Append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
            }
            sb.Append("\nlocationdescribe : ");
            sb.Append(location.LocationDescribe);                           // 位置语义化信息
            System.Collections.Generic.IList <Poi> list = location.PoiList; // POI数据
            if (list != null)
            {
                sb.Append("\npoilist size = : ");
                sb.Append(list.Count.ToString());
                foreach (Poi p in list)
                {
                    sb.Append("\npoi= : ");
                    sb.Append(p.Id + " " + p.Name + " " + p.Rank);
                }
            }
            System.Diagnostics.Debug.Write(sb.ToString());
        }
 public void OnReceiveLocation(BDLocation p0)
 {
 }
 void IBDLocationListener.OnReceivePoi(BDLocation p0)
 {
 }
Exemplo n.º 11
0
            public override void OnReceiveLocation(BDLocation lct)
            {
                if (lct == null)
                {
                    return;
                }

                try
                {
                    var msg = $"OnReceiveLocation:{lct.Latitude} Latitude:{lct.Longitude} Address:{lct.Country}{lct.Province}{lct.City}{lct.Address?.Street}";
                    Android.Util.Log.Info("位置:", msg);

                    //ToastUtils.ShowSingleToast(msg);

                    GlobalSettings.Latitude  = lct.Latitude;
                    GlobalSettings.Longitude = lct.Longitude;

                    new Thread(async() =>
                    {
                        if (lct != null && !GlobalSettings.IsNotConnected)
                        {
                            var _conn    = App.Resolve <LocalDatabase>();
                            var tracking = new TrackingModel()
                            {
                                StoreId          = Settings.StoreId,
                                BusinessUserId   = Settings.UserId,
                                BusinessUserName = Settings.UserRealName,
                                Latitude         = lct.Latitude,
                                Longitude        = lct.Longitude,
                                CreateDateTime   = DateTime.Now,
                                Province         = lct.Province,
                                County           = lct.Country,
                                City             = lct.City,
                                //Town = lct.Town,
                                Address = lct.Address?.Street
                            };

                            var gpsEvent = new GpsEvent()
                            {
                                Latitude   = lct.Latitude,
                                Longitude  = lct.Longitude,
                                CreateTime = DateTime.Now,
                                Address    = $"{lct.Country}{lct.Province}{lct.City}{lct.Address?.Street}"
                            };

                            var cg = await _conn.GpsEvents.CountAsync();
                            var lg = await _conn.LocationSyncEvents.CountAsync();

                            if (cg > 50)
                            {
                                await _conn.ResetGpsEvents();
                            }

                            if (lg > 50)
                            {
                                await _conn.ResetLocationSyncEvents();
                            }

                            //存储本地
                            if (!string.IsNullOrWhiteSpace(gpsEvent.Address))
                            {
                                await _conn.InsertAsync(gpsEvent);
                            }

                            if (!string.IsNullOrWhiteSpace(tracking.Address))
                            {
                                await _conn.InsertAsync(tracking);
                            }
                        }
                    }).Start();
                }
                catch (Java.Lang.Exception ex)
                {
                    Android.Util.Log.Error("上报", ex.Message);
                }
            }
Exemplo n.º 12
0
        /// <summary>
        /// 实现位置监听,实时缓存我的位置
        /// </summary>
        /// <param name="location"></param>
        public void OnReceiveLocation(BDLocation location)
        {
            if (stopped)
            {
                return;
            }

            System.Diagnostics.Debug.WriteLine("LocType: " + location.LocType);

            switch (location.LocType)
            {
            default: break;

            case BDLocation.TypeServerError:
            {
                System.Diagnostics.Debug.Print("服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因");
            }
            break;

            case BDLocation.TypeNetWorkException:
            {
                System.Diagnostics.Debug.Print("网络不同导致定位失败,请检查网络是否通畅");
            }
            break;

            case BDLocation.TypeCriteriaException:
            {
                System.Diagnostics.Debug.Print("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
            }
            break;

            case BDLocation.TypeGpsLocation:
            case BDLocation.TypeNetWorkLocation:
            case BDLocation.TypeOffLineLocation:
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("time : ");
                sb.Append(location.Time);
                sb.Append("\nerror code : ");
                sb.Append(location.LocType);
                sb.Append("\nlatitude : ");
                sb.Append(location.Latitude);
                sb.Append("\nlontitude : ");
                sb.Append(location.Longitude);
                sb.Append("\nradius : ");
                sb.Append(location.Radius);

                System.Diagnostics.Debug.Print(sb.ToString());

                BMap.MyLocationData loc = new BMap.MyLocationData.Builder()
                                          .Accuracy(location.Radius)
                                          .Direction(location.Direction)
                                          .Latitude(location.Latitude)
                                          .Longitude(location.Longitude)
                                          .Build();

                mapView.Map.SetMyLocationData(loc);

                ///位置更新
                LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs
                    {
                        Coordinate = new Coordinate(loc.Latitude, loc.Longitude),
                        Direction  = location.Direction,
                        Accuracy   = location.HasRadius ? location.Radius : double.NaN,
                        Altitude   = location.HasAltitude ? location.Altitude : double.NaN,
                        Satellites = location.SatelliteNumber,
                        Type       = location.LocTypeDescription,
                        Province   = location.Province,
                        City       = location.City,
                        District   = location.District,
                        Street     = location.Street,
                        Address    = location.AddrStr
                    });
                return;
            }
            }

            Failed?.Invoke(this, new LocationFailedEventArgs(location.LocType.ToString()));
        }