Inheritance: IGeocoordinate
コード例 #1
0
ファイル: PostItinerary.xaml.cs プロジェクト: kleitz/WPApp
        private async Task<GeoCoordinate> ShowMyCurrentLocationOnTheMap()
        {
            // Get my current location.
            Geolocator myGeolocator = new Geolocator();
            Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
            myGeocoordinate = myGeoposition.Coordinate;

            wayPoints.Add(new GeoCoordinate(myGeocoordinate.Latitude, myGeocoordinate.Longitude));
            //GeoCoordinate myxGeocoordinate = new GeoCoordinate(47.6785619, -122.1311156);

            myGeoCoordinate =
                CoordinateConverter.ConvertGeocoordinate(myGeocoordinate);

            // Make my current location the center of the Map.
            this.mapPostItinerary.Center = myGeoCoordinate;
            this.mapPostItinerary.ZoomLevel = 16;

            // Create a MapOverlay to contain the circle.
            startPointOverlay = MarkerDraw.DrawCurrentMapMarker(myGeoCoordinate);

            // Create a MapLayer to contain the MapOverlay.
            myLocationLayer = new MapLayer();
            myLocationLayer.Add(startPointOverlay);

            // Add the MapLayer to the Map.
            mapPostItinerary.Layers.Add(myLocationLayer);

            return myGeoCoordinate;
        }
コード例 #2
0
        //###################################################################################################################
        //################################################## Constructor ####################################################
        //###################################################################################################################

        public GeolocationSample (DateTimeOffset _startDateTime, Geocoordinate geocoordinate) 
        {
            this.MeasurementTime = geocoordinate.Timestamp.Subtract(_startDateTime);
            this.Latitude = geocoordinate.Point.Position.Latitude;
            this.Longitude = geocoordinate.Point.Position.Longitude;
            this.Altitude = geocoordinate.Point.Position.Altitude;
            this.Accuracy = geocoordinate.Accuracy;
            this.Speed = geocoordinate.Speed.HasValue ? geocoordinate.Speed.Value : 0d;
        }
コード例 #3
0
ファイル: Gps.cs プロジェクト: FlorianRappl/YAMP
 async static void InitialPosition(Sensor sensor)
 {
     try
     {
         var geopos = await sensor.GetGeopositionAsync();
         position = geopos.Coordinate;
     }
     catch { }
 }
コード例 #4
0
 private void AddMapIcon(Geocoordinate location, String name)
 {
     //Add an mapicon for the given location
     MapIcon mapIcon = new MapIcon();
     mapIcon.Location = location.Point;
     mapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
     mapIcon.Title = name;
     InputMap.MapElements.Add(mapIcon);
 }
コード例 #5
0
        public async Task<GoogleCivicAddress> ResolveAddressAsync(Geocoordinate coordinate)
        {
            if (coordinate == null)
                throw new ArgumentNullException("coordinate");

            var url = string.Format(CultureInfo.InvariantCulture, "http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=true", coordinate.Latitude, coordinate.Longitude);
            var wc = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
            var result = await wc.GetStringAsync(url);
            return ParseResult(result);
        }
コード例 #6
0
 public static GeoCoordinate ConvertGeocoordinateGreen(Geocoordinate geocoordinate)
 {
     return new GeoCoordinate
         (
         geocoordinate.Latitude,
         geocoordinate.Longitude,
         geocoordinate.Altitude ?? Double.NaN,
         geocoordinate.Accuracy,
         geocoordinate.AltitudeAccuracy ?? Double.NaN,
         geocoordinate.Speed ?? Double.NaN,
         geocoordinate.Heading ?? Double.NaN
         );
 }
コード例 #7
0
 public static GeoCoordinate ConvertGeocoordinate(Geocoordinate geocoordinate)
 {
     return new GeoCoordinate
         (
         geocoordinate.Point.Position.Latitude,
         geocoordinate.Point.Position.Longitude,
         geocoordinate.Point.Position.Altitude,
         geocoordinate.Accuracy,
         geocoordinate.AltitudeAccuracy ?? double.NaN,
         geocoordinate.Speed ?? double.NaN,
         geocoordinate.Heading ?? double.NaN
         );
 }
コード例 #8
0
ファイル: 1Map.xaml.cs プロジェクト: ITESO-Ulab/EMT_WP
 public static GeoCoordinate convertidirGeocoordinate(Geocoordinate geocoordenada)//Metodo que convierte de Geocoordinate a GeoCoordinate
 {
     return new GeoCoordinate
         (
         geocoordenada.Latitude,
         geocoordenada.Longitude,
         geocoordenada.Altitude ?? Double.NaN,
         geocoordenada.Accuracy,
         geocoordenada.AltitudeAccuracy ?? Double.NaN,
         geocoordenada.Speed ?? Double.NaN,
         geocoordenada.Heading ?? Double.NaN
         );
 }
        public static async Task<IEnumerable<ItemViewModel>> GeoSearchAsync(Geocoordinate coordinate)
        {
            var position = coordinate.Point.Position;
            var orderByFilter = $"geo.distance(LOCATION, geography'POINT({position.Longitude} {position.Latitude})')";

            var searchParameters = new SearchParameters()
            {
                Filter = "FEATURE_CLASS eq 'Trail'",
                OrderBy = new[]
                {
                    orderByFilter
                }
            };

            return await DoSearchAsync("*", searchParameters);
        }
コード例 #10
0
 public static Coordinate Create(Geocoordinate underlayed)
 {
     var c = new Coordinate();
     try { c.Alt = Convert.ToInt32(underlayed.Altitude); }
     catch { };
     try { c.HDOP = Convert.ToInt32(underlayed.Accuracy); }
     catch { };
     try { c.Course = Convert.ToInt32(underlayed.Heading); }
     catch { };
     try { c.Lat = underlayed.Latitude; }
     catch { };
     try { c.Lon = underlayed.Longitude; }
     catch { };
     try { c.Speed = underlayed.Speed.GetValueOrDefault(0); }
     catch { };
     try { c.Timestamp = Convert.ToInt32(underlayed.Timestamp.UtcDateTime.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); }
     catch { };
     return c;
 }
        /// <returns>Returns null if exited Stationary modus, else returns Report Interval in milliseconds (lazy or aggressive)</returns>
        public double? GetNewReportInterval(Position newPosition)
        {
            if (_previousPosition == null) // first position-update in stationary, always aggresive
            {
                _previousPosition = newPosition;
                return _stationaryPollingIntervalAggresive.TotalMilliseconds;
            }

            var distance = GetDistanceToStationary(newPosition);
            if (distance > _stationaryRadius)
            {
                // exit stationary
                _stationaryPosition = null;
                _stationaryGeocoordinate = null;
                return null;
            }
            var percentage = distance / _stationaryRadius;

            return percentage < 0.5 ? _stationaryPollingIntervalLazy.TotalMilliseconds : _stationaryPollingIntervalAggresive.TotalMilliseconds;
        }
        public static async Task<IEnumerable<ItemViewModel>> GeoSearchAsync(Geocoordinate coordinate, string filter = null)
        {
            var position = coordinate.Point.Position;
            var orderByFilter = $"geo.distance(LOCATION, geography'POINT({position.Longitude} {position.Latitude})')";
                       

            var searchParameters = new SearchParameters()
            {
                Filter = CreateFilter(filter),
                OrderBy = new[]
                {
                    orderByFilter
                },
                Facets = new[]
                {
                    FacetName
                }
            };

            return await DoSearchAsync("*", searchParameters);
        }
コード例 #13
0
        public static GeoCoordinate ToGeoCoordinate(this Geocoordinate geocoordinate)
        {
            if (geocoordinate == null)
            {
                return(null);
            }

            GeoCoordinate geoCoordinate = new GeoCoordinate()
            {
                // Per MSDN, http://msdn.microsoft.com/en-us/library/ee808821.aspx (not in the invidual properties, but rather this constructor)
                // Altitude, Course and Speed and VerticalAccuracy, if unknown, they are supposed to be NaN.
                Altitude           = geocoordinate.Altitude ?? double.NaN,
                Course             = geocoordinate.Heading ?? double.NaN,
                HorizontalAccuracy = geocoordinate.Accuracy,
                Latitude           = geocoordinate.Latitude,
                Longitude          = geocoordinate.Longitude,
                Speed            = geocoordinate.Speed ?? double.NaN,
                VerticalAccuracy = geocoordinate.AltitudeAccuracy ?? double.NaN,
            };

            return(geoCoordinate);
        }
コード例 #14
0
 public GpxCoordinate( Geocoordinate Position, DateTime Time )
 {
     this.Position = Position;
     this.Time = Time;
 }
 public void ExitStationary()
 {
     _stationaryGeocoordinate = null;
 }
コード例 #16
0
 public static double GetDistanceTo(this Geocoordinate a, Geocoordinate b)
 {
     return EarthRadiusInMeters * 2 * Math.Asin(Math.Min(1, Math.Sqrt((Math.Pow(Math.Sin((DiffRadian(a.Latitude, b.Latitude)) / 2.0), 2.0)
         + Math.Cos(ToRadian(a.Latitude)) * Math.Cos(ToRadian(b.Latitude)) * Math.Pow(Math.Sin((DiffRadian(a.Longitude, b.Longitude)) / 2.0), 2.0)))));
 }
コード例 #17
0
        private MvxGeoLocation CreateLocation(Geocoordinate coordinate)
        {
            var position = new MvxGeoLocation { Timestamp = coordinate.Timestamp };
            var coords = position.Coordinates;

            // TODO - allow nullables - https://github.com/slodge/MvvmCross/issues/94
            coords.Altitude = coordinate.Altitude ?? 0.0;
            coords.Latitude = coordinate.Latitude;
            coords.Longitude = coordinate.Longitude;
            coords.Speed = coordinate.Speed ?? 0.0;
            coords.Accuracy = coordinate.Accuracy;
            coords.AltitudeAccuracy = coordinate.AltitudeAccuracy ?? double.MaxValue;

            return position;
        }
コード例 #18
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (!IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
            {
                MessageBoxResult result =
                    MessageBox.Show("This app accesses your phone's location. Is that ok?",
                    "Location",
                    MessageBoxButton.OKCancel);
                IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = (result == MessageBoxResult.OK);
                IsolatedStorageSettings.ApplicationSettings.Save();
            }

            if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"])
            {
                geolocator = new Geolocator();
                geolocator.DesiredAccuracy = PositionAccuracy.High;
                geolocator.MovementThreshold = 1; // The units are meters.

                geolocator.StatusChanged += (sender, args) =>
                {
                    status = args.Status;
                    ShowLoc();
                };
                geolocator.PositionChanged += (sender, args) =>
                {
                    coordinate = args.Position.Coordinate;
                    ShowLoc();
                };
            }

            if (Motion.IsSupported)
            {
                motion = new Motion();
                motion.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20);
                motion.CurrentValueChanged += (sender, e2) => CurrentValueChanged(e2.SensorReading);

                // Try to start the Motion API.
                try
                {
                    motion.Start();
                }
                catch (Exception)
                {
                    MessageBox.Show("unable to start the Motion API.");
                }
            }

            Appointments appointments = new Appointments();
            appointments.SearchCompleted += (sender, e2) =>
            {
                DateList.ItemsSource = e2.Results.OrderBy(p => p.StartTime);
                Waiter(false);
            };
            appointments.SearchAsync(DateTime.Now, DateTime.Now.AddDays(7), null);
        }
コード例 #19
0
 public GeocoordinateModel(Geocoordinate geocoordinate)
 {
     this.GeoCoordinate = geocoordinate.ToGeoCoordinate();
     this.Timestamp = geocoordinate.Timestamp.UtcDateTime;
 }
コード例 #20
0
        private void PraseCityUsingBaiduAPI(Geocoordinate geocoordinate)
        {
            string url = string.Format(@"http://api.map.baidu.com/geocoder/v2/?ak={0}&location={1},{2}&output=json",
                Configmanager.BAIDUMAP_APPKEY, geocoordinate.Point.Position.Latitude, geocoordinate.Point.Position.Longitude);

            FormAction GeocodingBaiDuAction = new FormAction(url);
            GeocodingBaiDuAction.Run(false);
            GeocodingBaiDuAction.FormActionCompleted += (result, ss) =>
            {
                /*
                {"status":0,"result":{"location":{"lng":121.34878897239,"lat":31.219452183508},"formatted_address":"上海市闵行区仙霞西路地道","business":"华漕,虹桥机场","addressComponent":{"city":"上海市","country":"中国","direction":"","distance":"","district":"闵行区","province":"上海市","street":"仙霞西路地道","street_number":"","country_code":0},"poiRegions":[{"direction_desc":"\u5185","name":"\u4e0a\u6d77\u8679\u6865\u673a\u573a"}],"sematic_description":"上海虹桥机场内,许浦港东119米","cityCode":289}}
                */
                JToken jtoken = JToken.Parse(result);
                string status = jtoken["status"].ToString();
                if (string.Equals(status, "0"))
                {
                    string city = jtoken["result"]["addressComponent"]["city"].ToString().Replace("市", "");
                    //Save the Located City
                    AppSettings.Intance.LocationCity = city;
                }
            };
        }
 public void StartStationary(Position stationaryPosition, Geocoordinate geocoordinate)
 {
     _stationaryPosition = stationaryPosition;
     _stationaryGeocoordinate = geocoordinate;
 }
コード例 #22
0
 // Events --------
 // Geolocation
 void onGeolocationChanged(Geolocator sender, PositionChangedEventArgs args)
 {
     //Debug.WriteLine("AdMob.onGeolocationChanged: Called longitude=" + args.Position.Coordinate.Longitude +
     //                ", latitude=" + args.Position.Coordinate.Latitude);
     geocoordinate = args.Position.Coordinate;
 }
コード例 #23
0
        private async Task getCurrentLocation()
        {
            //Request the current location with the geolocator
            var accessStatus = await Geolocator.RequestAccessAsync();

            //Check the response type
            switch (accessStatus)
            {
                case GeolocationAccessStatus.Allowed:
                    //Getting location is enabled
                    Summary.Text = "Locating your current position...";
                    Geoposition pos = await geolocator.GetGeopositionAsync();
                    currentLocation = pos.Coordinate;
                    Summary.Text = "Location found, make an route";
                    Error.Text = "";

                    //Zooming to current location
                    InputMap.Center = currentLocation.Point;
                    InputMap.ZoomLevel = 8;
                    break;
                case GeolocationAccessStatus.Denied:
                    //Getting location is disabled, show a link to the settings
                    Summary.Text = "";
                    Hyperlink link = new Hyperlink();

                    Summary.Inlines.Add(new Run()
                    {
                        Text = "Access to current location denied."
                    });
                    Summary.Inlines.Add(new LineBreak());
                    Summary.Inlines.Add(new Run()
                    {
                        Text = "Check your "
                    });

                    link.Inlines.Add(new Run()
                    {
                        Text = "location settings",
                        Foreground = new SolidColorBrush(Colors.White)
                    });
                    link.NavigateUri = new Uri("ms-settings:privacy-location");

                    Summary.Inlines.Add(link);
                    break;
                case GeolocationAccessStatus.Unspecified:
                    Summary.Text = "An unexpected problem occured";
                    break;
            }
        }
コード例 #24
0
        /// <summary>
        /// Event handler for StatusChanged events. It is raised when the 
        /// location status in the system changes.
        /// </summary>
        /// <param name="sender">Geolocator instance</param>
        /// <param name="e">Statu data</param>
        async private void OnStatusChanged(Geolocator sender, StatusChangedEventArgs e)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                GeolocationPin.Status = e.Status;
                switch (e.Status)
                {
                    case PositionStatus.Ready:
                        // Location platform is providing valid data.
                        ShowStatus("Geolocation is ready", StatusType.Info, 5, 0);
                        break;

                    case PositionStatus.Initializing:
                        // Location platform is attempting to acquire a fix. 
                        ShowStatus("Initializing");
                        break;

                    case PositionStatus.NoData:
                        // Location platform could not obtain location data.
                        ShowStatus("No data", StatusType.Error, 5, 0);
                        break;

                    case PositionStatus.Disabled:
                        // The permission to access location data is denied by the user or other policies.
                        ShowStatus("Disabled", StatusType.Error, 5, 0);

                        // Show message to the user to go to location settings
                        //LocationDisabledMessage.Visibility = Visibility.Visible;

                        // Clear cached location data if any
                        CurrentPosition = null;
                        break;

                    case PositionStatus.NotInitialized:
                        // The location platform is not initialized. This indicates that the application 
                        // has not made a request for location data.
                        ShowStatus("Not initialized");
                        break;

                    case PositionStatus.NotAvailable:
                        // The location platform is not available on this version of the OS.
                        ShowStatus("Not available", StatusType.Error, 5, 0);
                        break;

                    default:
                        ShowStatus("Unknown", StatusType.Error, 5, 0);
                        GeolocationPin.Status = PositionStatus.NoData;
                        break;
                }
            });
        }
コード例 #25
0
ファイル: MainPage.xaml.cs プロジェクト: juyingnan/VS
 private string GetCoordinateString(Geocoordinate geocoordinate)
 {
     string positionString = string.Format("纬度: {0:0.0000}, 经度: {1:0.0000}, 误差: {2}m",
          geocoordinate.Latitude, geocoordinate.Longitude, geocoordinate.Accuracy);
     latitude = geocoordinate.Latitude;
     longitude = geocoordinate.Longitude;
     return positionString;
 }
コード例 #26
0
        async private void PositionChanged(Geolocator sender, PositionChangedEventArgs e)
        {
            //Event only gets called when geolocator has a location found
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                //Updating current location
                currentLocation = e.Position.Coordinate;

                //Updating mapicon of the current location
                for (int i = 0; i < InputMap.MapElements.Count; i++)
                {
                    if (InputMap.MapElements[i] is MapIcon)
                    {
                        MapIcon icon = (MapIcon)InputMap.MapElements[i];
                        if (icon.Title.Equals(nameCurrentLocation))
                        {
                            InputMap.MapElements.Remove(icon);
                            break;
                        }
                    }
                }

                AddMapIcon(currentLocation, nameCurrentLocation);
            });        
        }
        private UpdateScaledDistanceFilterResult UpdateScaledDistanceFilter(double? currentAvgSpeed, Geocoordinate geocoordinate)
        {
            var result = new UpdateScaledDistanceFilterResult(_scaledDistanceFilter.HasValue ? _scaledDistanceFilter.Value : 0);
            var lastPosition = _positionPath.GetLastPosition();
            result.Distance = lastPosition.DinstanceToPrevious;

            if (!lastPosition.Speed.HasValue || !currentAvgSpeed.HasValue)
            {
                _scaledDistanceFilter = _distanceFilter;
                return result;
            }

            if (lastPosition.DinstanceToPrevious.HasValue && (lastPosition.DinstanceToPrevious.Value < _distanceFilter || lastPosition.DinstanceToPrevious.Value < _stationaryRadius))
            {
                // too little movement, start Stationary and/or skip this position update

                if (lastPosition.DinstanceToPrevious.Value < _stationaryRadius)
                {
                    _stationaryManager.StartStationary(lastPosition, geocoordinate);
                    result.StartStationary = true;
                }
                result.SkipPositionBecauseOfDistance = true;
                return result;
            }

            result.NewScaledDistanceFilter = CalculateNewScaledDistanceFilter(currentAvgSpeed.Value);
            _scaledDistanceFilter = result.NewScaledDistanceFilter;
            return result;
        }
コード例 #28
0
        /// <summary>
        /// Parses geocoordinate retrieved from JS in form of colon-separated string
        /// </summary>
        /// <param name="serializedGeoposition">Serialized, colon-separated position</param>
        /// <returns>Geocoordinate</returns>
        private static Geocoordinate ParseGeocoordinate(string serializedPosition)
        {
            var dataSplit = serializedPosition.Split(':');

            var latitude  = double.Parse(dataSplit[0], CultureInfo.InvariantCulture);
            var longitude = double.Parse(dataSplit[1], CultureInfo.InvariantCulture);

            double?altitude = null;

            if (double.TryParse(dataSplit[2], NumberStyles.Float, CultureInfo.InvariantCulture, out double parsedAltitude))
            {
                altitude = parsedAltitude;
            }

            double?altitudeAccuracy = null;

            if (double.TryParse(dataSplit[3], NumberStyles.Float, CultureInfo.InvariantCulture, out double parsedAltitudeAccuracy))
            {
                altitudeAccuracy = parsedAltitudeAccuracy;
            }

            var accuracy = double.Parse(dataSplit[4], CultureInfo.InvariantCulture);

            double?heading = null;

            if (double.TryParse(dataSplit[5], NumberStyles.Float, CultureInfo.InvariantCulture, out var parsedHeading))
            {
                heading = parsedHeading;
            }

            double?speed = null;

            if (double.TryParse(dataSplit[6], NumberStyles.Float, CultureInfo.InvariantCulture, out var parsedSpeed))
            {
                speed = parsedSpeed;
            }

            var timestamp = DateTimeOffset.UtcNow;

            if (long.TryParse(dataSplit[7], NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedTimestamp))
            {
                timestamp = DateTimeOffset.FromUnixTimeMilliseconds(parsedTimestamp);
            }

            var geocoordinate = new Geocoordinate(
                latitude,
                longitude,
                accuracy,
                timestamp,
                point: new Geopoint(
                    new BasicGeoposition {
                Longitude = longitude, Latitude = latitude, Altitude = altitude ?? 0
            },
                    AltitudeReferenceSystem.Ellipsoid,            //based on https://www.w3.org/TR/geolocation-API/
                    Wgs84SpatialReferenceId),                     //based on https://en.wikipedia.org/wiki/Spatial_reference_system
                altitude: altitude,
                altitudeAccuracy: altitudeAccuracy,
                heading: heading,
                speed: speed);

            return(geocoordinate);
        }
コード例 #29
0
 /// <summary>
 /// Event handler for PositionChanged events. It is raised when
 /// a location is available for the tracking session specified.
 /// </summary>
 /// <param name="sender">Geolocator instance</param>
 /// <param name="e">Position data</param>
 async private void OnPositionChanged(Geolocator sender, PositionChangedEventArgs e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         if (e.Position == null)
         {
             ShowStatus("No Data", StatusType.Error, 5, 0);
         }
         else
         {
             CurrentPosition = e.Position.Coordinate;
         }
     });
 }
コード例 #30
0
 public static XLocation ConvertXLocation(Geocoordinate geocoordinate, XLocation existing)
 {
     geocoordinate.CopyProperties(existing);
     return existing;
 }
コード例 #31
0
        void _sendUpdate(Geocoordinate currentPosition = null, double accuracy = 0)
        {
            if (currentPosition != null)
            {
                CurrentLocation = LocationHelpers.ConvertXLocation(currentPosition, CurrentLocation);
                CurrentLocation.IsResolved = true;
            }
            else
            {
                CurrentLocation.IsResolved = false;
            }

            if (accuracy != 0)
            {
                CurrentLocation.Accuracy = Convert.ToInt32(accuracy);
            }


            _fire();

        }
コード例 #32
0
 public double GetDistanceTo(Geocoordinate other)
 {
     return _location.GetDistanceTo(new GeoCoordinate(other.Latitude, other.Longitude));
 }