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(); }
public string GetInfo(string search, string latitud, string longitude, string distance) { var sCoord = new GeoCoordinate(double.Parse("30"),double.Parse("30")); var eCoord = new GeoCoordinate(double.Parse("30")+10, double.Parse("30")+10); return "[{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":" + sCoord.GetDistanceTo(eCoord) + ", \"latitude\":\"20.6827248\", \"longitude\":\"-103.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + ",{\"idItem\": 2, \"idCategory\" : 1, \"name\":\"producto2\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\":1,\"cost\":20.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":" + sCoord.GetDistanceTo(eCoord) + ", \"latitude\":\"20.6827248\", \"longitude\":\"-103.4466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-103.5466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 2, \"idCategory\" : 1, \"name\":\"producto2\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\":1,\"cost\":20.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-103.6466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-103.7466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 2, \"idCategory\" : 1, \"name\":\"producto2\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\":1,\"cost\":20.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-103.8466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-103.9466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 2, \"idCategory\" : 1, \"name\":\"producto2\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\":1,\"cost\":20.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.2466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 2, \"idCategory\" : 1, \"name\":\"producto2\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\":1,\"cost\":20.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.4466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.5466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 2, \"idCategory\" : 1, \"name\":\"producto2\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\":1,\"cost\":20.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.2466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}" + //",{\"idItem\": 1, \"idCategory\" : 1, \"name\":\"producto1\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\": 1,\"cost\":16.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.3466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}"+ //",{\"idItem\": 2, \"idCategory\" : 1, \"name\":\"producto2\", \"category\":\"categoria 1\",\"description\":\"la description es indescriptible porque tenemos razones para inventar lo inventaro jaj que mamadas\", \"hasCost\":1,\"cost\":20.5,\"active\":1, \"image\":\"http://192.168.1.110/finditout/images/image_1.jpg\"" + ",\"finditoutName\":\"dominio6\",\"distance\":300.3, \"latitude\":\"20.6827248\", \"longitude\":\"-104.6466798\", \"logo\":\"logo1\", \"allImages\":\"http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item1.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item2.jpg@@http://192.168.1.110/finditout/img/FindOut/FindItOutName/Item/item3.jpg\"}"+ "]"; }
// 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); }
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(); }
/// <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; }
/// <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; }
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; }
public void CalculateDistances(GeoCoordinate clientCoordinate) { foreach (var server in Servers) { server.Distance = clientCoordinate.GetDistanceTo(server.GeoCoordinate); } }
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; }
/// <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; } }
//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); }
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; } } } }
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; } }
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); }
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; }
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; }
public double GetDistance(Location other) { var firstCordinate = new GeoCoordinate(this.Latitude, this.Longitude); var secondCordinate = new GeoCoordinate(other.Latitude, other.Longitude); double distance = firstCordinate.GetDistanceTo(secondCordinate); return distance; }
public static double CalculateDistanceInMeters(double sourceLat, double sourceLng, double destLat, double destLng) // from http://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates { var sourceLocation = new GeoCoordinate(sourceLat, sourceLng); var targetLocation = new GeoCoordinate(destLat, destLng); return sourceLocation.GetDistanceTo(targetLocation); }
public static double GetDistance(this IList <GPSPoint> points) { return(gpsPointsOperation(points, (previous, current) => { var coordinate1 = new GeoCoordinate(previous.Latitude, previous.Longitude, previous.Altitude); var coordinate2 = new GeoCoordinate(current.Latitude, current.Longitude, current.Altitude); return coordinate2.GetDistanceTo(coordinate1); })); }
public double GetDistance(double latA, double longA, double latB, double longB) { var StartPoint = new GeoCoordinate(latA, longA); var EndPoint = new GeoCoordinate(latB, longB); var DistanceKLM = StartPoint.GetDistanceTo(EndPoint) / 1000; var DistanceKM = Math.Round(DistanceKLM * .5399568); return(DistanceKM); }
public void RelateUserToGroups(RelateUserToGroupsDto newRelations) { var user = this._unitOfWork.UserRepository.GetUserById(newRelations.UserId); if (user == null) { throw new ArgumentException("User with id:" + newRelations.UserId + " doesn't exist."); } if (user.Groups == null) { user.Groups = new List <Group>(); } if (user.HistoryGroups == null) { user.HistoryGroups = new List <HistoryGroup>(); } var currentLocation = new GeoCoordinate(newRelations.Latitude, newRelations.Longitude); var areaEntities = this._unitOfWork.AreaRepository.GetAreas() .Where(x => currentLocation.GetDistanceTo(new GeoCoordinate(x.Latitude, x.Longitude)) <= (int)x.Radius); // 1. Fetch all the groups that belong to the user and are around {newRelations.Latitude, newRelations.Longitude} var groupsForUserAroundCurrentLocation = areaEntities .SelectMany(a => a.Groups) .Where(gr => gr.Users.Contains(user)); // 2. Fetch all the groups that came from the request var groupSubscriptionsThatCameFromTheRequest = this._unitOfWork.GroupRepository.GetGroups() .Where(gr => newRelations.GroupsUserSubscribes.Contains(gr.Id)); // 3. Determine what groups have been unsubscribed: Everything that is in (1) and doesn't belong to (2) var forUserAroundCurrentLocation = groupsForUserAroundCurrentLocation as Group[] ?? groupsForUserAroundCurrentLocation.ToArray(); var unsubscribedGroups = forUserAroundCurrentLocation.Where(gr => !groupSubscriptionsThatCameFromTheRequest.Contains(gr)).ToList(); // 4. Determine what groups have bee added and are new: Everything that is in (2) and doesn't belong to (1) var newlySubscribedGroups = groupSubscriptionsThatCameFromTheRequest.Where(gr => !forUserAroundCurrentLocation.Contains(gr)); // 5. Each group in (3) has to be removed from current user subscriptions this.DisconnectUserFromUnsubscribedGroups(unsubscribedGroups, user); // 6. Each group in (4) has to be added to the current user subscriptions this.ConnectUserToNewlySubscribedGroups(newlySubscribedGroups, user); this._unitOfWork.Save(); if (this._configuration.AutomaticallyCleanupGroupsAndAreas) { this.DeactivateGroupsWithNoUsersInsideOfThem(unsubscribedGroups, newRelations.UserId); this._unitOfWork.Save(); } }
/// <summary> /// Function gets, in miles, the distance between two Waypoints /// </summary> /// <param name="otherPoint">Point to calculate distance to</param> /// <returns>Miles between the waypoints</returns> public double DistanceToNextWayPoint(ICoordinate otherPoint) { //using the system.device GeoCoordinate class calculate the distance var thisGeoCoordinate = new GeoCoordinate(Position.Latitude, Position.Longitude); var otherGeoCoordinate = new GeoCoordinate(otherPoint.Latitude, otherPoint.Longitude); //function does meters, change to miles return(thisGeoCoordinate.GetDistanceTo(otherGeoCoordinate) / 1609.344); }
public static async Task <Station> GetNearestStation(string contract, GeoCoordinate gpsPosition) { Station[] stations = await GetStationsByContract(contract); double min = gpsPosition.GetDistanceTo(new GeoCoordinate(stations[0].position.latitude, stations[0].position.longitude)); Station closestStation = new Station(); for (int i = 0; i < stations.Length; i++) { double distance = gpsPosition.GetDistanceTo(new GeoCoordinate(stations[i].position.latitude, stations[i].position.longitude)); if (distance < min) { min = distance; closestStation = stations[i]; } } return(closestStation); }
private bool CalcularDistancia(double latOrigem, double lonOrigem, double latUsuario, double lonUsuario, double alcance) { var localOrigem = new GeoCoordinate(latOrigem, lonOrigem); var localUsuario = new GeoCoordinate(latUsuario, lonUsuario); var distancia = localOrigem.GetDistanceTo(localUsuario); return(distancia <= alcance); }
public Double GetDistance(double sLatitude, double sLongitude, double eLatitude, double eLongitude) { var sCoord = new GeoCoordinate(sLatitude, sLongitude); var eCoord = new GeoCoordinate(eLatitude, eLongitude); double DistanceInMeter = sCoord.GetDistanceTo(eCoord); double DistanceInMile = DistanceInMeter * 0.000621371; return(DistanceInMile); }
double calculateDistanceUsingGeoCoordinates(double lon1, double lat1, double lon2, double lat2) { GeoCoordinate c1 = new GeoCoordinate(lat1, lon1); GeoCoordinate c2 = new GeoCoordinate(lat2, lon2); double distanceInKm = c1.GetDistanceTo(c2) / 1000; double miles = distanceInKm * 0.621371192; return(miles); }
/// <summary> /// calculate the distance between two cities (in Kilometers) /// </summary> /// <param name="CityName1"></param> /// <param name="CityName2"></param> /// <returns>double</returns> public double CalculateDistanceBetweenCities(string CityName1, string CityName2) { var CityInfo1 = CityCatalogue.Where(c => c.Key.Contains(CityName1.ToLower())).FirstOrDefault().Value; var CityInfo2 = CityCatalogue.Where(c => c.Key.Contains(CityName2.ToLower())).FirstOrDefault().Value; GeoCoordinate c1 = new GeoCoordinate(CityInfo1.Latitude, CityInfo1.Longitude); GeoCoordinate c2 = new GeoCoordinate(CityInfo2.Latitude, CityInfo2.Longitude); return(c1.GetDistanceTo(c2) / 1000); //in KM }
public double GetDistanceTo(double latitude, double longitude) { if (OriginLocation == null) { return(0); } return(Math.Round(OriginLocation.GetDistanceTo(new GeoCoordinate(latitude, longitude)) / 1609.344, 2)); }
private float calcDistance(float lat1, float lat2, float long1, float long2) { GeoCoordinate loc1 = new GeoCoordinate(lat1, long1); GeoCoordinate loc2 = new GeoCoordinate(lat2, long2); double distance = loc1.GetDistanceTo(loc2) / 1000; return(Convert.ToSingle(distance)); }
/// <summary> /// The distance between the two coordinates, in meters. /// </summary> /// <param name="loc">The second location</param> /// <returns>The distance in meters</returns> public double GetDistanceTo(Localizzazione loc) { var coord1 = new GeoCoordinate(this.Lat, this.Lon); var coord2 = new GeoCoordinate(loc.Lat, loc.Lon); var distance = coord1.GetDistanceTo(coord2); return(distance); }
public static int DistanceDeuxLampadaire(Lampadaire lampadaire1, Lampadaire lampadaire2) {//calcul entre la distance de deux lampadaire var sCoord = new GeoCoordinate(lampadaire1.Latitude, lampadaire1.Longitude); var eCoord = new GeoCoordinate(lampadaire2.Latitude, lampadaire2.Longitude); int res = (int)sCoord.GetDistanceTo(eCoord); return(res); }
static void Main(string[] args) { logger.LogInfo("Log initialized"); var lines = File.ReadAllLines(csvPath); logger.LogInfo($"Lines: {lines[0]}"); var parser = new TacoParser(); var locations = lines.Select(parser.Parse).ToArray(); ITrackable taco1 = null; ITrackable taco2 = null; double distance = 0; TacoBell newLocation = new TacoBell() { }; var LocA = new GeoCoordinate(); var LocB = new GeoCoordinate(); for (int i = 0; i < locations.Length; i++) { LocA.Latitude = locations[i].Location.Latitude; LocA.Longitude = locations[i].Location.Longitude; for (int j = 0; j < locations.Length; j++) { LocB.Latitude = locations[j].Location.Latitude; LocB.Longitude = locations[j].Location.Longitude; var newDistance = LocA.GetDistanceTo(LocB); if (newDistance > distance) { taco1 = locations[i]; taco2 = locations[j]; distance = newDistance; } } } Console.WriteLine($"The two taco bells the futherest from each other are { taco1.Name} && {taco2.Name} "); // TODO: Find the two Taco Bells in Alabama that are the furthest from one another. // HINT: You'll need two nested forloops }
/// <summary> /// Get Distance between Source and Destination Airports /// </summary> /// <param name="AirportData"></param> /// <param name="Source"></param> /// <param name="Destination"></param> /// <returns></returns> public double GetDistance(AirportDetails AirportData, string Source, string Destination) { var SourceCity = AirportData.AirportDetailsList.Where(x => x.name != null && x.name.ToLower().Equals(Source.ToLower())).ToList().First(); var DestinationCity = AirportData.AirportDetailsList.Where(x => x.name != null && x.name.ToLower().Equals(Destination.ToLower())).ToList().First(); var sCoord = new GeoCoordinate(Convert.ToDouble(SourceCity.lat), Convert.ToDouble(SourceCity.lon)); var eCoord = new GeoCoordinate(Convert.ToDouble(DestinationCity.lat), Convert.ToDouble(DestinationCity.lon)); return(sCoord.GetDistanceTo(eCoord) / 1000); }
public int getNearestAttr(GeoCoordinate cor) { double range = -1; int retVal = -1; for (int i = 0; i < this.otherAttr.Count; i++) { GeoCoordinate myCoor = new GeoCoordinate(Double.Parse(this.otherAttr[i].location.First.ToString()) , Double.Parse(this.otherAttr[i].location.Second.ToString())); if (range == -1 || range > cor.GetDistanceTo(myCoor)) { range = cor.GetDistanceTo(myCoor); retVal = i; } } return(retVal); }
private static decimal?CalculateProximity(GeoCoordinate origin, AddressDTO destination) { if (origin == null || destination.Longitude == null || destination.Latitude == null) { return(null); } return(((decimal)Math.Round(origin.GetDistanceTo(new GeoCoordinate(destination.Latitude.Value, destination.Longitude.Value)) / MetersPerMile * 10)) / 10); }
public double GetDistance(Location other) { var firstCordinate = new GeoCoordinate(this.Latitude, this.Longitude); var secondCordinate = new GeoCoordinate(other.Latitude, other.Longitude); double distance = firstCordinate.GetDistanceTo(secondCordinate); return(distance); }
public static double harversineDist3(double lon1, double lat1, double lon2, double lat2) { GeoCoordinate c1 = new GeoCoordinate(lat1, lon1); GeoCoordinate c2 = new GeoCoordinate(lat2, lon2); double distanceInKm = c1.GetDistanceTo(c2) / 1000; return(distanceInKm); }
public static double CalcDistanceTo(GeoCoordinate current, GeoCoordinate target) { if (current.IsUnknown == true || target.IsUnknown == true) { return(double.NaN); } return(current.GetDistanceTo(target)); }
private async Task tryCreateStopLabelsAt(MapPage page, GeoCoordinate currentLocation, IEnumerable <Stop> mandatoryStops = null) { if (!lowMarkedLocations.Any(loc => currentLocation.GetDistanceTo(loc) < App.Config.LowStopsRadius * 0.8)) { lowMarkedLocations.Add(currentLocation); //highMarkedLocations.Add(currentLocation); await createStopLabelsAt(page, currentLocation, mandatoryStops, radius : App.Config.LowStopsRadius); } }
public override double GetDistance(PointLatLng point2) { GeoCoordinate c1 = new GeoCoordinate(point.Lat, point.Lng); GeoCoordinate c2 = new GeoCoordinate(point2.Lat, point2.Lng); double distance = c1.GetDistanceTo(c2); return(distance); }
static void Main(string[] args) { // TODO: Find the two Taco Bells in Alabama that are the furthest from one another. // HINT: You'll need two nested for loops // DON'T FORGET TO LOG YOUR STEPS // Grab the path from the name of your file logger.LogInfo("Log initialized"); // use File.ReadAllLines(path) to grab all the lines from your csv file var lines = File.ReadAllLines(csvPath); // Log and error if you get 0 lines and a warning if you get 1 line logger.LogInfo($"Lines: {lines[0]}"); // Create a new instance of your TacoParser class var parser = new TacoParser(); // Grab an IEnumerable of locations using the Select command: var locations = lines.Select(parser.Parse); var locations = lines.Select(parser.Parse).ToArray(); // Now, here's the new code // Create two `ITrackable` variables with initial values of `null`. These will be used to store your two taco bells that are the furthest from each other. ITrackable TacoBell1 = null; ITrackable TacoBell2 = null; // Create a `double` variable to store the distance double LargestDistance = 0; // Include the Geolocation toolbox, so you can compare locations: `using GeoCoordinatePortable;` // Do a loop for your locations to grab each location as the origin (perhaps: `locA`) foreach (ITrackable Restuarant in locations) { // Create a new corA Coordinate with your locA's lat and long GeoCoordinate locA = new GeoCoordinate(Restuarant.Location.Latitude, Restuarant.Location.Longitude); foreach (ITrackable TacoRestuarant in locations) { // Now, do another loop on the locations with the scope of your first loop, so you can grab the "destination" location (perhaps: `locB`) // Create a new Coordinate with your locB's lat and long GeoCoordinate locB = new GeoCoordinate(TacoRestuarant.Location.Latitude, TacoRestuarant.Location.Longitude); // Now, compare the two using `.GetDistanceTo()`, which returns a double double DistanceBetweenResturants = locA.GetDistanceTo(locB); // If the distance is greater than the currently saved distance, update the distance and the two `ITrackable` variables you set above if (DistanceBetweenResturants > LargestDistance) { TacoBell1 = Restuarant; TacoBell2 = TacoRestuarant; LargestDistance = DistanceBetweenResturants; } } } // Once you've looped through everything, you've found the two Taco Bells furthest away from each other. Console.WriteLine(TacoBell1.Name); Console.WriteLine(TacoBell2.Name); Console.WriteLine(LargestDistance); }
{/// <summary> /// have 2 earth coordiantes using longitude and lattiude /// calculate their distance /// use class GeoCode in namespace System.Device /// </summary> /// <param name="args"></param> static void Main(string[] args) { var sCoord = new GeoCoordinate(34.7818, 32.0853); //coordinate of tel avivi var eCoord = new GeoCoordinate(35.2137, 31.7683); //coordinate of jerusalem var distance = sCoord.GetDistanceTo(eCoord); Console.WriteLine($"your distance is {distance} meters"); }
public double CalculateDistance(GlobalPoint start, GlobalPoint end) { GeoCoordinate pin1 = new GeoCoordinate(start.Latitude, start.Longitude); GeoCoordinate pin2 = new GeoCoordinate(end.Latitude, end.Longitude); double distanceBetween = pin1.GetDistanceTo(pin2); return(distanceBetween); }
public string GetNearestLocation(double latitude, double longitude, int k) { GeoCoordinate actualCoordinate = new GeoCoordinate(latitude, longitude); List <LocationEntity> orderedLocations = Locations.ToList().OrderBy(entity => actualCoordinate.GetDistanceTo(entity.Coordinate)).ToList(); List <LocationEntity> kNearest = orderedLocations.Take(k).ToList(); List <IGrouping <string, LocationEntity> > grouped = kNearest.GroupBy(entity => entity.GeographicalName).OrderBy(g => g.Count()).ToList(); IGrouping <string, LocationEntity> nearestList = grouped.First(); LocationEntity nearest = nearestList.OrderBy(entity => actualCoordinate.GetDistanceTo(entity.Coordinate)).First(); double minDistance = actualCoordinate.GetDistanceTo(nearest.Coordinate); var nearestGeographicalName = nearestList.Key; double distanceInMiles = DataConversion.ConvertMetersToMiles(minDistance); string direction = ""; return($"{distanceInMiles:0.0} mi {direction} {nearestGeographicalName}"); }
public static double latlong2DistX(double lastLat, double lastLng, double thisLat, double thisLng) { // 先緯度再經度 var sCoord = new GeoCoordinate(lastLat, lastLng); var eCoord = new GeoCoordinate(thisLat, thisLng); // 回傳兩者距離 return(sCoord.GetDistanceTo(eCoord)); }
public static double GetDistanceBetweenToPoint(double lat1, double long1, double lat2, double long2) { var locA = new GeoCoordinate(lat1, long1); var locB = new GeoCoordinate(lat2, long2); //פונקציה שמחזירה את המרחק מ2 הנקודות במטרים double distance = locA.GetDistanceTo(locB); return(distance); }
public Airport GetClosestAirport(GeoCoordinate coordinate) { Airport closestAirport = Airports[0]; GeoCoordinate airportCoordinate = new GeoCoordinate(closestAirport.Latitude, closestAirport.Longitude); double closestDistance = coordinate.GetDistanceTo(airportCoordinate); foreach (Airport airport in Airports) { airportCoordinate = new GeoCoordinate(airport.Latitude, airport.Longitude); double airportDistance = coordinate.GetDistanceTo(airportCoordinate); if (airportDistance < closestDistance) { closestAirport = airport; closestDistance = airportDistance; } } return(closestAirport); }
public static double CalculateDistanceInMeters(double sourceLat, double sourceLng, double destLat, double destLng) // from http://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates { var sourceLocation = new GeoCoordinate(sourceLat, sourceLng); var targetLocation = new GeoCoordinate(destLat, destLng); return(sourceLocation.GetDistanceTo(targetLocation)); }
public double CalculateDistance(Location a, Location b) { var geoA = new GeoCoordinate(a.Latitude, a.Longitude); var geoB = new GeoCoordinate(b.Latitude, b.Longitude); var distInMeters = geoA.GetDistanceTo(geoB); var distInMiles = distInMeters * 0.000621371; return distInMiles + 0.001; }
public bool IsMatch(Property agencyProperty, Property databaseProperty) { Ensure.NotNull(agencyProperty, "agencyProperty"); Ensure.NotNull(databaseProperty, "databaseProperty"); var sCoord = new GeoCoordinate((double)agencyProperty.Latitude, (double)agencyProperty.Longitude); var eCoord = new GeoCoordinate((double)databaseProperty.Latitude, (double)databaseProperty.Longitude); return sCoord.GetDistanceTo(eCoord) <= sensitivityInMetres; }
private string CalculateDistance(GeoCoordinate userLocation, AspNetUser aspNetUser) { if (aspNetUser.Longitude.HasValue && aspNetUser.Latitude.HasValue) { var pairedLocation = new GeoCoordinate(aspNetUser.Latitude.Value, aspNetUser.Longitude.Value); var distance = userLocation.GetDistanceTo(pairedLocation)*0.0016; // metres return string.Format("{0} miles from you", distance.ToString("N0")); } return string.Empty; }
public int CalculateDistanceBetweenLocations(GeoLocation searchLocation, double latitude, double longitude) { if (searchLocation == null) { return 0; } var geoCoordinate1 = new GeoCoordinate(searchLocation.Latitude, searchLocation.Longitude); var geoCoordinate2 = new GeoCoordinate(latitude, longitude); var distanceInMiles = (geoCoordinate1.GetDistanceTo(geoCoordinate2) / 1000) / KilometresPerMile; return (int)Math.Round(distanceInMiles); }
/// <summary> /// Returns the distance from this region's closest bounds in meters. /// </summary> public double DistanceFrom(double latitude, double longitude) { double closestRegion = double.MaxValue; GeoCoordinate location = new GeoCoordinate(latitude, longitude); foreach (var bounds in this.RegionBounds) { GeoCoordinate regionLocation = new GeoCoordinate(bounds.Latitude, bounds.Longitude); closestRegion = Math.Min(closestRegion, regionLocation.GetDistanceTo(location)); } return closestRegion; }
public void Should_be_within_the_range_of_half_a_metre_to_microsofts_implementation() { var sut = new Coordinate(33, 151); var other = new Coordinate(32.999098M, 150.998147M); //200 metres away var ms = new GeoCoordinate(33, 151); var otherMs = new GeoCoordinate(32.999098, 150.998147); var result = sut.GetDistanceInMetres(other); var expected = ms.GetDistanceTo(otherMs); result.ShouldBeInRange(expected - .5, expected + .5); }
internal static int GetGoogleZoomLevel(double lat1, double lon1, double lat2, double lon2) { GeoCoordinate sCoord = new GeoCoordinate(lat1, lon1); GeoCoordinate eCoord = new GeoCoordinate(lat2, lon2); double distanceInKm = sCoord.GetDistanceTo(eCoord)/1000; if (distanceInKm < 0.1) return 18; else if (distanceInKm >= 0.1 && distanceInKm < 1.0) return 16; else if (distanceInKm >= 1.0 && distanceInKm < 2.0) return 14; else return 13; }
/// <summary> /// Gets a Bing Maps zoom level that should let the user easily see /// both points of interest. I'm using this to show both the current /// location of the phone plus a destination place. /// </summary> /// <param name="geo1">First point of interest.</param> /// <param name="geo2">Second point of interest.</param> /// <param name="pixelsBetween">The number of ideal pixels between the /// two points. For a screen which may be 480 pixels wide, figure with /// pin size on display, maybe provide a value like 210 pixels.</param> /// <returns>Returns a zoom level for use with the Bing Maps control or /// Bing Maps static map REST API.</returns> public static double GetZoomLevelShowingPoints(GeoCoordinate geo1, GeoCoordinate geo2, double pixelsBetween) { var distanceBetween = geo1.GetDistanceTo(geo2); var averageLatitude = (geo1.Latitude + geo2.Latitude) / 2; for (int i = 1; i < 20; i++) { var latitudeResolutionPerPixel = ResolutionMetersPerPixel(averageLatitude, i); var pixelDifferenceInMeters = pixelsBetween * latitudeResolutionPerPixel; if (pixelDifferenceInMeters < distanceBetween) { return i; } } return 19; // max. }
public Sted FindClosestSted(GeoCoordinate myLocation) { var closestDistance = double.PositiveInfinity; Sted closestSted = null; foreach (var geoCoordinate in _stedsDictionary.Keys) { var distanceToThis = myLocation.GetDistanceTo(geoCoordinate); if (distanceToThis <= closestDistance) { closestDistance = distanceToThis; closestSted = _stedsDictionary[geoCoordinate]; } } if (closestSted == null) throw new Exception("Did not find closest sted"); return closestSted; }
public void AddLocation(GeoCoordinate l) { System.Diagnostics.Debug.WriteLine("Distance " + distance); try { distance += l.GetDistanceTo(this.route.Locations[this.route.Locations.Count - 1]); } catch { // dont add any distances } route.Locations.Add(l); locations.Add(new Location(l.Latitude, l.Longitude)); }
public object Convert(object value, Type targetType, object parameter, string language) { double[] tabConverter = (double[]) value; if (tabConverter != null && tabConverter.Length == 2) { double[] localisation = (double[]) App.Current.Resources["localisation"]; var coordUser = new GeoCoordinate(localisation[1], localisation[0]); var coordDistributeur = new GeoCoordinate(tabConverter[0], tabConverter[1]); return Math.Round(coordUser.GetDistanceTo(coordDistributeur)/1000, 2).ToString() + " Km"; } else { return "Pas de coordonnées"; } }
//What to do if position changed? private void TrackPosition(GeoPositionChangedEventArgs<GeoCoordinate> e) { var coord = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude); if (_line.Path.Count > 0) { //Find the previous point and measure the distance travelled. var previousPoint = _line.Path.Last(); var distance = coord.GetDistanceTo(previousPoint); //Compute total distance travelled. _kilometres += distance / 1000.0; txbDistance2.Text = String.Format("{0:f2} km", _kilometres); txbCalories2.Text = String.Format("{0:f2}", _kilometres * 65); } Map.Center = coord; _line.Path.Add(coord); }