当前位置: 首页>>代码示例>>C#>>正文


C# GeoCoordinate.GetDistanceTo方法代码示例

本文整理汇总了C#中GeoCoordinate.GetDistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# GeoCoordinate.GetDistanceTo方法的具体用法?C# GeoCoordinate.GetDistanceTo怎么用?C# GeoCoordinate.GetDistanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GeoCoordinate的用法示例。


在下文中一共展示了GeoCoordinate.GetDistanceTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Guard

        public void Guard(Route patrolRoute)
        {
            if (!flightTimer.Enabled)
            {
                // drone is not flying
                this.TakeOff();
            }
            while (BatteryRemaining > Drone.BatteryLowLimit)
            {
                GeoCoordinate position = new GeoCoordinate(this.Position.Latitude, this.Position.Longitude);
                double distanceToPatrolEnd = position.GetDistanceTo(patrolRoute.RouteEnd);
                double distanceToPatrolStart = position.GetDistanceTo(patrolRoute.RouteStart);

                if (distanceToPatrolEnd < 20)
                {
                    this.Destination = new WayPoint() {Latitude= patrolRoute.RouteStart.Latitude, Longitude = patrolRoute.RouteStart.Longitude, Altitude=0} ;
                }
                else if (distanceToPatrolStart < 20)
                {
                    this.Destination = new WayPoint() { Latitude = patrolRoute.RouteEnd.Latitude, Longitude = patrolRoute.RouteEnd.Longitude, Altitude = 0 };
                }
                this.Fly();
           }
            // Battery limit is low, go back to base
            this.Destination = new WayPoint() { Latitude = patrolRoute.RouteStart.Latitude, Longitude = patrolRoute.RouteStart.Longitude, Altitude = 0 };
            this.Land();
        }
开发者ID:guadacasuso,项目名称:DroneFireFighters,代码行数:27,代码来源:DroneEmulator.cs

示例2: GetDistanceBetweenTwoLocalizations

		public double GetDistanceBetweenTwoLocalizations(double latitude1, double longitude1, double latitude2, double longitude2) {
			var firstLocation = new GeoCoordinate(latitude1, longitude1);
			var secondLocation = new GeoCoordinate(latitude2, longitude2);
			var distance = Math.Round(firstLocation.GetDistanceTo(secondLocation) / 1000, 2);

			return distance;
		}
开发者ID:MarcinSzyszka,项目名称:MobileSecondHand,代码行数:7,代码来源:CoordinatesCalculator.cs

示例3: CalculateDistanceInMeters

        // from http://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates
        public static double CalculateDistanceInMeters(double sourceLat, double sourceLng, double destLat, double destLng)
        {
            var sourceLocation = new GeoCoordinate(sourceLat, sourceLng);
            var targetLocation = new GeoCoordinate(destLat, destLng);

            return sourceLocation.GetDistanceTo(targetLocation);
        }
开发者ID:RouHim,项目名称:Pokemon-Go-Rocket-API,代码行数:8,代码来源:LocationUtils.cs

示例4: GetLocationsByCoordinates

            public static List<Location> GetLocationsByCoordinates(GeoCoordinate coordinates)
            {
                const double metersInMile = 1609.34;

                var locations = new List<Location> ();
                var filteredLocations = new List<Location> ();

                using(var conn = Db.Instance.GetConnection()) {
                    locations.AddRange(conn.Table<Location>().ToList());
                }

                // Only add locations within 100 miles of coordinates
                foreach (var location in locations) {
                    GeoCoordinate gc = new GeoCoordinate { Latitude = (double)location.Latitude, Longitude = (double)location.Longitude };

                    if (gc.GetDistanceTo (coordinates) / metersInMile < 100)
                    {
                        filteredLocations.Add (location);
                    }
                }

                // Order by distance, nearest first
                return filteredLocations.OrderBy(l => {
                    GeoCoordinate gc = new GeoCoordinate { Latitude = (double)l.Latitude, Longitude = (double)l.Longitude };
                    return gc.GetDistanceTo(coordinates);
                }).ToList();
            }
开发者ID:cdmedia,项目名称:heinzight,代码行数:27,代码来源:LocationDAO.cs

示例5: CloestToMultipleLocation

        /// <summary>
        /// Find single stop nearest to multiple location
        /// </summary>
        /// <param name="location"></param>
        /// <param name="radius"></param>
        public static Stop CloestToMultipleLocation(List<double[]> locations, decimal radius = 500)
        {
            List<Stop> list = new List<Stop>();

            using (ATDataContext context = new ATDataContext())
            {
                list = context.Stops.ToList();
            }

            GeoCoordinate endpoint = new GeoCoordinate();
            GeoCoordinate startpoint = new GeoCoordinate();
            double distance = 0;
            double new_distance = 0;
            Stop result = new Stop();

            foreach (Stop s in list)
            {
                new_distance = 0;
                startpoint = new GeoCoordinate(s.Latitude.GetValueOrDefault(), s.Longitude.GetValueOrDefault());

                foreach(var location in locations)
                {
                    endpoint = new GeoCoordinate(location[0], location[1]);
                    new_distance += startpoint.GetDistanceTo(endpoint);
                }

                if (list.IndexOf(s) == 0 || new_distance < distance)
                {
                    distance = new_distance;
                    result = s;
                }
            }

            return result;
        }
开发者ID:ZiLinNZ,项目名称:GoAuckland,代码行数:40,代码来源:FindStops.cs

示例6: Calculate

        public static double Calculate(double lat1,double lat2,double long1,double long2)
        {
            var geoCoordFirst = new GeoCoordinate(lat1, long1);
            var geoCoordSecond = new GeoCoordinate(lat2,long2);

            var distance = geoCoordFirst.GetDistanceTo(geoCoordSecond);
         
            return distance;

            var R = 6371000; // earths diameter metres
            var latRadian1 = DegreeToRadian(lat1);
            var latRadian2 = DegreeToRadian(lat2);
            var deltaLat = DegreeToRadian(lat2- lat1);
            var deltaLong = DegreeToRadian(long2- long1);

            var a = Math.Sin(deltaLat / 2) * Math.Sin(deltaLat / 2) +
                    Math.Cos(lat1) * Math.Cos(lat2) *
                    Math.Sin(deltaLong / 2) * Math.Sin(deltaLong / 2);

            var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

            distance = R * c;

            return distance;
        }
开发者ID:wIksS,项目名称:TrackingSystem,代码行数:25,代码来源:DistanceCalculator.cs

示例7: CheckForTargetLocation

        public static async void CheckForTargetLocation(int HitchBotID, int LocationID)
        {
            using (var db = new Models.Database())
            {
                var location = db.Locations.First(l => l.ID == LocationID);
                var hitchbot = db.hitchBOTs.First(h => h.ID == HitchBotID);
                var TargetLocations = db.TwitterLocations.Where(l => l.HitchBot.ID == HitchBotID && l.Status == null).Include(l => l.TargetLocation);

                foreach (hitchbotAPI.Models.TwitterLocationTarget thisTargetLocation in TargetLocations)
                {
                    var currentLocation = new GeoCoordinate(location.Latitude, location.Longitude);
                    var targetLocation = new GeoCoordinate(thisTargetLocation.TargetLocation.Latitude, thisTargetLocation.TargetLocation.Longitude);
                    if (currentLocation.GetDistanceTo(targetLocation) <= thisTargetLocation.RadiusKM * 1000)
                    {
                        int TweetID = await Helpers.TwitterHelper.PostTweetWithLocation(HitchBotID, LocationID, thisTargetLocation.TweetText);
                        Task<int> WeatherTweet = TwitterHelper.PostTweetWithLocationAndWeather(HitchBotID, LocationID);
                        LinkTargetLocationToTweet(TweetID, thisTargetLocation.ID);
                        await WeatherTweet;
                        break;
                    }
                }

            }

        }
开发者ID:ElrHolis,项目名称:hitchBOT,代码行数:25,代码来源:LocationHelper.cs

示例8: Distance

        public static double Distance(double lat, double lng, XLocation b)
        {
            var aCord = new GeoCoordinate(lat, lng);
            var bCord = new GeoCoordinate(b.Latitude, b.Longitude);

            return aCord.GetDistanceTo(bCord);
        }
开发者ID:jakkaj,项目名称:Xamling-Core,代码行数:7,代码来源:LocationHelpers.cs

示例9: GetEdgesByLocation

        public List<Edge> GetEdgesByLocation(string _lat, string _lng)
        {
            _lat = _lat.Replace(".", ",");
            _lng = _lng.Replace(".", ",");
            double lat;
            decimal lat2 = Convert.ToDecimal(_lat);
            int lng = Convert.ToInt32(_lng.Substring(0, _lng.IndexOf(',')));

            if (Double.TryParse(_lat.Substring(0, _lat.IndexOf(',') + 1), out lat))
            {
                GeoCoordinate geoCoordinate = new GeoCoordinate(lat, lng);
                decimal dec = Math.Round(lat2, 1);
                var stations = db.Stations.Where(x => (Int32)x.StationLong == lng && Decimal.Round(x.StationLat,1) == dec);
                List<Edge> edges = new List<Edge>();
                foreach (var station in stations)
                {
                    double distance =
                        geoCoordinate.GetDistanceTo(new GeoCoordinate(Convert.ToDouble(station.StationLat),
                                                                      Convert.ToDouble(station.StationLong)));

                    Edge edge = new Edge{Distance = Convert.ToDecimal(distance), EndStationId = station.ID, EndStation = station, IsActive = true};
                    edges.Add(edge);
                }

                return edges;
            }

            return null;
        }
开发者ID:Christind,项目名称:ucn-3semproject-dm79-group1,代码行数:29,代码来源:EdgeRepository.cs

示例10: calculateDistance

 //calculates the distance between two points (each one with a latitude and longitude value)
 public static double calculateDistance(double sLatitude, double sLongitude, double eLatitude, double eLongitude)
 {
     var sCoord = new GeoCoordinate(sLatitude, sLongitude);
     var eCoord = new GeoCoordinate(eLatitude, eLongitude);
     //GetDistanceTo is a function provided by the System.Device.Location Library
     return Math.Round(sCoord.GetDistanceTo(eCoord) / 1000, 2);
 }
开发者ID:BennyFischer,项目名称:nomofv2,代码行数:8,代码来源:GeoCalculator.cs

示例11: CalculateDistances

 public void CalculateDistances(GeoCoordinate clientCoordinate)
 {
     foreach (var server in Servers)
     {
         server.Distance = clientCoordinate.GetDistanceTo(server.GeoCoordinate);
     }
 }
开发者ID:xenoputtss,项目名称:NSpeedTest,代码行数:7,代码来源:ServersList.cs

示例12: AroundSingleLocation

        /// <summary>
        /// Find multiple stops based on radius
        /// </summary>
        /// <param name="location"></param>
        /// <param name="radius"></param>
        public static List<Stop> AroundSingleLocation(double[] location, double radius = 500)
        {
            List<Stop> list = new List<Stop>();
            List<Stop> filtered_list = new List<Stop>();

            using (ATDataContext context = new ATDataContext())
            {
                list = context.Stops.ToList();
            }

            GeoCoordinate endpoint = new GeoCoordinate(location[0], location[1]);
            GeoCoordinate startpoint = new GeoCoordinate();

            foreach (Stop s in list)
            {
                startpoint = new GeoCoordinate(s.Latitude.GetValueOrDefault(), s.Longitude.GetValueOrDefault());

                if (startpoint.GetDistanceTo(endpoint) < radius)
                {
                    filtered_list.Add(s);
                }
            }

            return filtered_list;
        }
开发者ID:ZiLinNZ,项目名称:GoAuckland,代码行数:30,代码来源:FindStops.cs

示例13: OnLocationChanged

        /// <summary>
        /// OnLocationChanged
        /// </summary>
        /// <param name="location"></param>
        public void OnLocationChanged(Location location)
        {
            double lat = location.Latitude;
            double lon = location.Longitude;

            _lat.Text = lat.ToString();
            _lon.Text = lon.ToString();

            var currentloc = new GeoCoordinate(lat, lon);

            foreach (var v in _storeLocations)
            {
                var storelocation = new GeoCoordinate(v.Value.Latitude, v.Value.Longitude);
                var distance = currentloc.GetDistanceTo(storelocation);
                _distanceTo.Text = distance.ToString();

                Context context = this;
                Android.Content.Res.Resources res = context.Resources;
                string minRadius = res.GetString(Resource.String.minRadiusinMeters);

                if (distance < Convert.ToInt16(minRadius))
                {
                    new AlertDialog.Builder(this)
                     .SetMessage("Hey you are near to store, happy shopping!..")
                     .SetNeutralButton("Ok", delegate { }).Show();
                }
                return;
            }
        }
开发者ID:Avinashlikes,项目名称:PUMAs,代码行数:33,代码来源:HomeActivity.cs

示例14: Watcher_PositionChanged

    private void Watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
    {
      var coord = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);

      if (_line.Path.Count > 0)
      {
        var previousPoint = _line.Path.Last();
        var distance = coord.GetDistanceTo(previousPoint);
        var millisPerKilometer = (1000.0 / distance) * (System.Environment.TickCount - _previousPositionChangeTick);
        _kilometres += distance / 1000.0;

        paceLabel.Text = TimeSpan.FromMilliseconds(millisPerKilometer).ToString(@"mm\:ss");
        distanceLabel.Text = string.Format("{0:f2} km", _kilometres);
        caloriesLabel.Text = string.Format("{0:f0}", _kilometres * 65); // an average of 65 calories burned per kilometer

                PositionHandler handler = new PositionHandler();
        var heading = handler.CalculateBearing(new Position(previousPoint), new Position(coord));
        Map.SetView(coord, Map.ZoomLevel, heading, MapAnimationKind.Parabolic);

        ShellTile.ActiveTiles.First().Update(new IconicTileData()
        {
          Title = "WP8Runner",
          WideContent1 = string.Format("{0:f2} km", _kilometres),
          WideContent2 = string.Format("{0:f0} calories", _kilometres * 65), // an average of 65 calories burned per kilometer
        });
      }
      else
      {
        Map.Center = coord;
      }

      _line.Path.Add(coord);
      _previousPositionChangeTick = System.Environment.TickCount;
    }
开发者ID:padmick,项目名称:WindowsPhoneProject,代码行数:34,代码来源:MainPage.xaml.cs

示例15: Filter

        public void Filter(UserSearchPipelineResult pipelineResult, UserSearchPipelineRequest request)
        {
            if (pipelineResult == null) throw new ArgumentNullException("pipelineResult");
            if (request == null) throw new ArgumentNullException("request", "Location data is required");
            if (request.LocationData == null) throw new ArgumentNullException("request", "Location data is required");

            var geo = new GeoCoordinate(request.LocationData.Latitude, request.LocationData.Longitude);

            foreach (var user in pipelineResult.Users)
            {
                var distanceTo = (float) geo.GetDistanceTo(new GeoCoordinate(user.Latitude, user.Longitude));

                float miles = distanceTo / _metersToMiles;

                var res = (int) Math.Round(miles, 0, MidpointRounding.AwayFromZero);

                float locationMultiplier = (Constants.LOCATION_MAX_MILES - res) * Constants.LOCATION_MILE_MULTIPLIER;

                if (Math.Abs(locationMultiplier) < float.Epsilon) //float precision - if not 0
                {
                    locationMultiplier = float.Epsilon;
                }

                user.Score *= locationMultiplier;
            }
        }
开发者ID:scottccoates,项目名称:CliqFlip,代码行数:26,代码来源:AssignLocationScoreFilter.cs


注:本文中的GeoCoordinate.GetDistanceTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。