public static double Distance(GpsLocation location1, GpsLocation location2) { return Distance(location1.Latitude, location1.Longitude, location2.Latitude, location2.Longitude); }
public async Task <IEnumerable <BusStop> > GetBusStopsInCircleAsync(GpsLocation location, double radius) { var requestUrl = new StringBuilder(serviceUrl); requestUrl.AppendFormat("?StopAlso=True&Circle={0},{1},{2}&ReturnList=StopPointName,StopID,StopCode1,StopCode2,StopPointIndicator,StopPointState,Towards,Latitude,Longitude,LineName", location.Latitude, location.Longitude, radius); var client = new System.Net.Http.HttpClient(); var response = Deserialize(await client.GetStringAsync(requestUrl.ToString())); var busStopLineInfo = new Dictionary <string, HashSet <string> >(); var busStops = new List <BusStop>(); foreach (var item in response) { var itemType = Convert.ToInt32(item[0]); // read bus stop info if (itemType == 0) { var busStop = new BusStop { Name = item[1] as string, Id = item[2] as string, Code = item[3] as string, Code2 = item[4] as string, Towards = item[5] as string, Indicator = item[6] as string, State = Convert.ToInt32(item[7]), Location = new GpsLocation(Convert.ToDouble(item[8]), Convert.ToDouble(item[9])) }; // filter out ghost stops (without any codes or buses) if (busStop.Code != null || busStop.Code2 != null) { busStops.Add(busStop); } } // read line info if (itemType == 1) { var lineInfo = item[10] as string; if (!string.IsNullOrEmpty(lineInfo)) { var stopId = item[2] as string; HashSet <string> linesInfo; if (!busStopLineInfo.TryGetValue(stopId, out linesInfo)) { linesInfo = new HashSet <string>(); busStopLineInfo.Add(stopId, linesInfo); } linesInfo.Add(lineInfo); } } } // add line info to bus stops foreach (var busStop in busStops) { if (busStopLineInfo.ContainsKey(busStop.Id)) { var lineInfo = string.Concat(busStopLineInfo[busStop.Id].OrderBy(i => i, busRouteComparer).Select(i => i + ",")); busStop.LineInfo = lineInfo.Remove(lineInfo.Length - 1, 1); } } return(busStops); }
public static double Distance(GpsLocation location1, GpsLocation location2) { return(Distance(location1.Latitude, location1.Longitude, location2.Latitude, location2.Longitude)); }