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


C# TripThruCore.Location类代码示例

本文整理汇总了C#中TripThruCore.Location的典型用法代码示例。如果您正苦于以下问题:C# Location类的具体用法?C# Location怎么用?C# Location使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Main

        static void Main()
        {
            Location fromLocation = new Location(-22.910194, -43.212211);
            Location toLocation = new Location(-22.9105337, -43.2123576);

            double Lat = fromLocation.Lat - toLocation.Lat;
            double Lng = fromLocation.Lng - toLocation.Lng;

            var result = Math.Sqrt(Math.Pow(Lat, 2) + Math.Pow(Lng, 2));
            int ocho = 9;
            /*

            var partnerConfigurations = GetPartnersConfigurations();

            using (var sr = new StreamReader("App_Data\\Geo-Routes.txt"))
            {
                var lines = sr.ReadToEnd();
                MapTools.routes = JsonConvert.DeserializeObject<Dictionary<string, Route>>(lines) ??
                                  new Dictionary<string, Route>();
            }
            using (var sr = new StreamReader("App_Data\\Geo-Location-Names.txt"))
            {
                var lines = sr.ReadToEnd();
                MapTools.locationNames = JsonConvert.DeserializeObject<Dictionary<string, string>>(lines) ??
                                         new Dictionary<string, string>();
            }
            using (var sr = new StreamReader("App_Data\\Geo-Location-Addresses.txt"))
            {
                var lines = sr.ReadToEnd();
                MapTools.locationAddresses = JsonConvert.DeserializeObject<Dictionary<string, Pair<string, string>>>(lines) ??
                                             new Dictionary<string, Pair<string, string>>();
            }

            foreach (var possibleTrip in partnerConfigurations.SelectMany(partnerConfiguration => partnerConfiguration.Fleets.ElementAt(0).PossibleTrips))
            {
                MapTools.GetRoute(possibleTrip.Start, possibleTrip.End);
            }

            var routesString = JsonConvert.SerializeObject(MapTools.routes);
            var locationNamesString = JsonConvert.SerializeObject(MapTools.locationNames);
            var locationAddresses = JsonConvert.SerializeObject(MapTools.locationAddresses);

            File.WriteAllText("App_Data\\Geo-Routes.txt", String.Empty);
            using (var sr = new StreamWriter("App_Data\\Geo-Routes.txt"))
            {
                sr.Write(routesString);
            }
            File.WriteAllText("App_Data\\Geo-Location-Names.txt", String.Empty);
            using (var sr = new StreamWriter("App_Data\\Geo-Location-Names.txt"))
            {
                sr.Write(locationNamesString);
            }
            File.WriteAllText("App_Data\\Geo-Location-Addresses.txt", String.Empty);
            using (var sr = new StreamWriter("App_Data\\Geo-Location-Addresses.txt"))
            {
                sr.Write(locationAddresses);
            }
             * */
        }
开发者ID:TripThru,项目名称:Gateway,代码行数:59,代码来源:1397810076$Program.cs

示例2: Driver

 public Driver(string name, PartnerFleet PartnerFleet = null, Location location = null)
     : base(name)
 {
     if (PartnerFleet != null)
         PartnerFleet.AddDriver(this);
     this.PartnerFleet = PartnerFleet;
     this.location = location;
     lastUpdate = DateTime.UtcNow;
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:9,代码来源:1396654558$PartnerGateway.cs

示例3: DecodePolylinePoints

        private static List<Location> DecodePolylinePoints(string encodedPoints)
        {
            if (encodedPoints == null || encodedPoints == "") return null;
            List<Location> poly = new List<Location>();
            char[] polylinechars = encodedPoints.ToCharArray();
            int index = 0;

            int currentLat = 0;
            int currentLng = 0;
            int next5bits;
            int sum;
            int shifter;

            try
            {
                while (index < polylinechars.Length)
                {
                    // calculate next latitude
                    sum = 0;
                    shifter = 0;
                    do
                    {
                        next5bits = (int)polylinechars[index++] - 63;
                        sum |= (next5bits & 31) << shifter;
                        shifter += 5;
                    } while (next5bits >= 32 && index < polylinechars.Length);

                    if (index >= polylinechars.Length)
                        break;

                    currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);

                    //calculate next longitude
                    sum = 0;
                    shifter = 0;
                    do
                    {
                        next5bits = (int)polylinechars[index++] - 63;
                        sum |= (next5bits & 31) << shifter;
                        shifter += 5;
                    } while (next5bits >= 32 && index < polylinechars.Length);

                    if (index >= polylinechars.Length && next5bits >= 32)
                        break;

                    currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
                    Location p = new Location(Convert.ToDouble(currentLat) / 100000.0, Convert.ToDouble(currentLng) / 100000.0);
                    poly.Add(p);
                }
            }
            catch (Exception)
            {
                // log it
            }
            return poly;
        }
开发者ID:TripThru,项目名称:Gateway,代码行数:56,代码来源:1397824053$Program.cs

示例4: GetRoute

        public static Route GetRoute(Location from, Location to)
        {
            var key = Route.GetKey(from, to);
            var route = StorageManager.GetRoute(key);
            if (route != null)
                return route;
            const double metersToMiles = 0.000621371192;
            const int maxDuration = 10;
            var doc = new XmlDocument();
            var elapse = new TimeSpan(0, 0, 0);
            double totalDistance = 0;
            var url = "http://maps.googleapis.com/maps/api/directions/xml?origin=" + from.Lat + ", " + from.Lng + "&destination=" + to.Lat + ", " + to.Lng + "&sensor=false&units=imperial";
            doc.Load(url);
            var status = doc.SelectSingleNode("//DirectionsResponse/status");

            if (status == null || status.InnerText == "ZERO_RESULTS" || status.InnerText == "OVER_QUERY_LIMIT")
            {
                Logger.LogDebug("Google request error", status != null ? status.InnerText : "status is null");
                throw new Exception("Bad route request");
            }
            var waypoints = new List<Waypoint> {new Waypoint(@from, new TimeSpan(0), 0)};
            var legs = doc.SelectNodes("//DirectionsResponse/route/leg");

            foreach (XmlNode leg in legs)
            {
                var stepNodes = leg.SelectNodes("step");
                foreach (XmlNode stepNode in stepNodes)
                {

                    var duration = int.Parse(stepNode.SelectSingleNode("duration/value").InnerText);
                    var distance = double.Parse(stepNode.SelectSingleNode("distance/value").InnerText) * metersToMiles;
                    var duration2 = new TimeSpan(0, 0, int.Parse(stepNode.SelectSingleNode("duration/value").InnerText));
                    var end = new Location(double.Parse(stepNode.SelectSingleNode("end_location/lat").InnerText), double.Parse(stepNode.SelectSingleNode("end_location/lng").InnerText));
                    var totalDistanceTemp = totalDistance;
                    totalDistance += distance;
                    var timeSpanTemp = elapse;
                    elapse += duration2;

                    if (duration > maxDuration)
                    {
                        var polyline = stepNode.SelectSingleNode("polyline/points").InnerText;
                        var locations = DecodePolylinePoints(polyline);
                        waypoints.AddRange(IncreaseLocationsEnumerable(locations, duration, timeSpanTemp.TotalSeconds, distance, totalDistanceTemp));
                    }
                    else
                    {
                        waypoints.Add(new Waypoint(end, elapse, totalDistance));
                    }
                }
            }

            waypoints.Add(new Waypoint(to, elapse, totalDistance));
            route = new Route(waypoints.ToArray());
            StorageManager.SaveRoute(route);
            return route;
        }
开发者ID:TripThru,项目名称:Gateway,代码行数:56,代码来源:MapTools.cs

示例5: GetReverseGeoLoc

 // http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
 public static string GetReverseGeoLoc(Location location)
 {
     lock (locationNames)
     {
         string key = location.getID();
         if (locationNames.ContainsKey(key))
             return locationNames[key];
         return GetReverseGeoLocationNameFromMapService(location);
     }
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:11,代码来源:1397817436$MapTools.cs

示例6: GetReverseGeoLocAddress

 public static Pair<string, string> GetReverseGeoLocAddress(Location location)
 {
     lock (locationAddresses)
     {
         string key = location.getID();
         if (locationAddresses.ContainsKey(key))
             return locationAddresses[key];
         return GetReverseGeoAddressFromMapService(location);
     }
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:10,代码来源:1397889938$MapTools.cs

示例7: IncreaseGranularityDistance

 private static IEnumerable<Location> IncreaseGranularityDistance(Location from, Location to, double maxLatLng)
 {
     var locations = new List<Location>();
     var lat = from.Lat - to.Lat;
     var lng = from.Lng - to.Lng;
     var latCount = from.Lat;
     var lngCount = from.Lng;
     var result = Math.Sqrt(Math.Pow(lat, 2) + Math.Pow(lng, 2)); //Calculamos la hipotenusa.
     if (result > maxLatLng)//Preguntamos si es necesario Granular
     {
         var repeatTimes = (uint)(result / maxLatLng); //Obtenemos las veces que se repetira el proceso.
         var stepLat = lat / repeatTimes;
         var stepLng = lng / repeatTimes;
         for (var i = 1; i < repeatTimes; i++)
         {
             latCount -= stepLat;
             lngCount -= stepLng;
             locations.Add(new Location(latCount, lngCount));
         }
     }
     locations.Add(new Location(to.Lat, to.Lng));
     return locations;
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:23,代码来源:1397824053$Program.cs

示例8: GetRoute

        public static Route GetRoute(Location from, Location to)
        {
            lock (routes)
            {
                var key = Route.GetKey(from, to);
                if (routes.ContainsKey(key))
                    return routes[key];
                const double metersToMiles = 0.000621371192;
                const int maxDuration = 10;
                var doc = new XmlDocument();
                var elapse = new TimeSpan(0, 0, 0);
                double totalDistance = 0;
                var url = "http://maps.googleapis.com/maps/api/directions/xml?origin=" + from.Lat + ", " + from.Lng + "&destination=" + to.Lat + ", " + to.Lng + "&sensor=false&units=imperial";
                doc.Load(url);
                var status = doc.SelectSingleNode("//DirectionsResponse/status");

                if (status == null || status.InnerText == "ZERO_RESULTS")
                    return null;
                var waypoints = new List<Waypoint> {new Waypoint(@from, new TimeSpan(0), 0)};
                var legs = doc.SelectNodes("//DirectionsResponse/route/leg");

                foreach (XmlNode leg in legs)
                {
                    var stepNodes = leg.SelectNodes("step");
                    foreach (XmlNode stepNode in stepNodes)
                    {

                        var duration = int.Parse(stepNode.SelectSingleNode("duration/value").InnerText);
                        var distance = double.Parse(stepNode.SelectSingleNode("distance/value").InnerText) * metersToMiles;
                        var duration2 = new TimeSpan(0, 0, int.Parse(stepNode.SelectSingleNode("duration/value").InnerText));
                        var end = new Location(double.Parse(stepNode.SelectSingleNode("end_location/lat").InnerText), double.Parse(stepNode.SelectSingleNode("end_location/lng").InnerText));
                        var totalDistanceTemp = totalDistance;
                        totalDistance += distance;
                        var timeSpanTemp = elapse;
                        elapse += duration2;

                        if (duration > maxDuration)
                        {
                            var polyline = stepNode.SelectSingleNode("polyline/points").InnerText;
                            var locations = DecodePolylinePoints(polyline);

                            waypoints.AddRange(IncreaseGranularityInPolylineList(locations, duration, maxDuration, timeSpanTemp.TotalSeconds, distance, totalDistanceTemp));

                        }
                        else
                        {
                            waypoints.Add(new Waypoint(end, elapse, totalDistance));
                        }
                    }
                }

                waypoints.Add(new Waypoint(to, elapse, totalDistance));
                var route = new Route(waypoints.ToArray());
                routes.Add(key, route);
                return route;
            }
        }
开发者ID:TripThru,项目名称:Gateway,代码行数:57,代码来源:1397817436$MapTools.cs

示例9: FleetServesLocation

 public bool FleetServesLocation(Location l)
 {
     foreach (Zone z in coverage)
     {
         if (z.IsInside(l))
             return true;
     }
     return false;
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:9,代码来源:1396654558$PartnerGateway.cs

示例10: NotifyForeignPartner

 private void NotifyForeignPartner(Status status, Location driverLocation, DateTime? eta)
 {
     Logger.Log("Since trip has foreign dependency, notify partner through TripThru");
     Logger.Tab();
     Gateway.UpdateTripStatusRequest request = new Gateway.UpdateTripStatusRequest(
         clientID: partner.ID,
         tripID: ID,
         status: status,
         driverLocation: driverLocation,
         eta: eta
     );
     partner.tripthru.UpdateTripStatus(request);
     Logger.Untab();
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:14,代码来源:1396654558$PartnerGateway.cs

示例11: IncreaseGranularityDistance

        private static IEnumerable<Location> IncreaseGranularityDistance(Location from, Location to, double maxLatLng)
        {
            var locations = new List<Location>();

            double Lat = from.Lat - to.Lat;
            double Lng = from.Lng - from.Lat;
            var latCount = from.Lat;
            var lngCount = from.Lng;
            var result = Math.Sqrt(Math.Pow(Lat, 2) + Math.Pow(Lng, 2)); //Calculamos la hipotenusa.
            if (result > maxLatLng)//Preguntamos si es necesario Granular
            {
                var repeatTimes = (int)(result/maxLatLng); //Obtenemos las veces que se repetira el proceso.
                var stepLat = Lat / repeatTimes;
                var stepLng = Lng / repeatTimes;
                for (var i = 0; i < repeatTimes; i++)
                {
                    latCount += stepLat;
                    lngCount += stepLng;
                    locations.Add(new Location(latCount,lngCount));
                }
            }
            return null;
            /*
            List<Waypoint> wayPoints = new List<Waypoint>();

            double granularity = duration / maxDuration;
            double stepDistance = (distance / granularity) + totalDistance;
            double stepDistaceCount = 0;
            double durationCount = totalDuration;
            double stepLat = from.Lat - to.Lat;
            double stepLng = from.Lng - to.Lng;
            double subStepLat = stepLat / granularity;
            double subStepLng = stepLng / granularity;

            for (int i = 0; i <= (granularity - 1); i++)
            {
                from.Lat -= subStepLat;
                from.Lng -= subStepLng;
                Location location = new Location(from.Lat, from.Lng);

                durationCount += maxDuration;
                stepDistaceCount += stepDistance;

                TimeSpan timeSpan = new TimeSpan(0, 0, (int)durationCount);
                wayPoints.Add(new Waypoint(location, timeSpan, stepDistaceCount));
            }
            wayPoints.Add(new Waypoint(from, new TimeSpan(0, 0, ((int)totalDuration + duration)), stepDistaceCount));

            return wayPoints;
             */
        }
开发者ID:TripThru,项目名称:Gateway,代码行数:51,代码来源:1397813264$MapTools.cs

示例12: Zone

 public Zone(Location center, double radius)
 {
     this.Center = center;
     this.Radius = radius;
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:5,代码来源:1396867459$Gateway.cs

示例13: IsInside

 public bool IsInside(Location l)
 {
     double lat1 = DegreesToRadians(Center.Lat);
     double lng1 = DegreesToRadians(Center.Lng);
     double lat2 = DegreesToRadians(l.Lat);
     double lng2 = DegreesToRadians(l.Lng);
     double dlon = lng2 - lng1;
     double dlat = lat2 - lat1;
     double a = Math.Pow(Math.Sin(dlat / 2.0), 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(dlon / 2.0), 2);
     double c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
     double d = 3961.0 * c; // (where 3961 is the radius of the Earth in miles
     return d < Radius;
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:13,代码来源:1396867459$Gateway.cs

示例14: Equals

 public bool Equals(Location l, double tolerance = .005)
 {
     double distance = GetDistance(l);
     return distance < tolerance;
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:5,代码来源:1396867459$Gateway.cs

示例15: UpdateTripStatusRequest

 public UpdateTripStatusRequest(string clientID, string tripID, Status status, Location driverLocation = null, DateTime? eta = null)
 {
     this.clientID = clientID;
     this.tripID = tripID;
     this.status = status;
     this.driverLocation = driverLocation;
     this.eta = eta;
 }
开发者ID:TripThru,项目名称:Gateway,代码行数:8,代码来源:1396867459$Gateway.cs


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