public PointLayer GetPointLayerByBounds(double neLat, double neLng, double swLat, double swLng, int page = 1, string[] ds = null, string[] tags = null) { PhotoSearchOptions searchOptions = new PhotoSearchOptions(); searchOptions.Licenses.Add(LicenseType.AttributionCC); searchOptions.Licenses.Add(LicenseType.AttributionShareAlikeCC); searchOptions.Licenses.Add(LicenseType.AttributionNoDerivativesCC); searchOptions.Licenses.Add(LicenseType.NoKnownCopyrightRestrictions); BoundaryBox bndry = new BoundaryBox(); if (neLat > swLat) { bndry.MinimumLatitude = swLat; bndry.MaximumLatitude = neLat; } else { bndry.MinimumLatitude = neLat; bndry.MaximumLatitude = swLat; } if (neLng > swLng) { bndry.MinimumLongitude = swLng; bndry.MaximumLongitude = neLng; } else { bndry.MinimumLongitude = neLng; bndry.MaximumLongitude = swLng; } searchOptions.BoundaryBox = bndry; if (!(tags == null || tags.Length < 1)) { searchOptions.Tags = string.Join(",", tags); searchOptions.TagMode = TagMode.AllTags; } searchOptions.Accuracy = GeoAccuracy.Street; searchOptions.PerPage = pageSize; searchOptions.SortOrder = PhotoSearchSortOrder.InterestingnessDescending; searchOptions.Extras |= PhotoSearchExtras.Geo; searchOptions.Extras |= PhotoSearchExtras.OwnerName; searchOptions.Extras |= PhotoSearchExtras.CountFaves; searchOptions.Extras |= PhotoSearchExtras.DateTaken; searchOptions.Extras |= PhotoSearchExtras.Description; searchOptions.Extras |= PhotoSearchExtras.Tags; searchOptions.Extras |= PhotoSearchExtras.SquareUrl; searchOptions.Page = page; PhotoCollection flickrPhotos = api.PhotosSearch(searchOptions); PointLayer result = new PointLayer(); result.DataSource = this.DataSource; result.TotalResults = flickrPhotos.Total; result.Page = flickrPhotos.Page; result.PageCount = flickrPhotos.Pages; result.Points = PointsFromPhotoCollection(flickrPhotos); result.PageSize = pageSize; return result; }
public PointLayer GetPointLayerByBounds(double neLat, double neLng, double swLat, double swLng, int page = 1, string[] ds = null, string[] tags = null) { var latCenter = (neLat + swLat) / 2; var lonCenter = (neLng + swLng) / 2; var dlat = neLat - swLat; var dlon = neLng - swLng; var a = Math.Pow(Math.Sin(dlat / 2), 2) + Math.Cos(neLat) * Math.Cos(swLat) * Math.Pow(Math.Sin(dlon / 2), 2); var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); var radius = _earthRadius * c / 2 * _radiusMod; //The .9 is just to make it a bit smaller. We'll end up missing the corners a bit, but oh well. var activities = new Activities(latCenter.ToString(), lonCenter.ToString(), radius.ToString()); var retval = new PointLayer() { DataSource = this.DataSource, Page = 1, PageCount = 1, Points = new List<Point>(), TotalResults = 0, }; foreach (var activity in activities.ToList()) { var newPoint = new Point() { DataSource = this.DataSource, Latitude = Convert.ToDouble(activity["lat"].ToString()), Longitude = Convert.ToDouble(activity["lon"].ToString()), Properties = new Dictionary<string,object>(), }; //newPoint.Properties.Add("details", activity); newPoint.AddTag("Activity"); var eventId = TryToConvert.ToInt(activity["EventID"]); var tourId = TryToConvert.ToInt(activity["TourID"]); if (eventId.HasValue) { newPoint.Id = "E" + eventId.Value.ToString(); newPoint.Title = activity["EventName"].ToString(); newPoint.AddTag("Event"); newPoint.Properties.Add("Type", "Event"); var startDate = activity["EventStartDate"].ToString(); var endDate = activity["EventEndDate"].ToString(); if (startDate == endDate) { newPoint.Properties.Add("Start Date", startDate); } else { newPoint.Properties.Add("Start Date", startDate); newPoint.Properties.Add("End Date", endDate); } newPoint.Properties.Add("Description", activity["EventDescription"].ToString()); } else if (tourId.HasValue) { newPoint.Id = "T" + tourId.Value.ToString(); newPoint.Title = activity["TourName"].ToString(); newPoint.AddTag("Tour"); newPoint.Properties.Add("Type", "Tour"); newPoint.Properties.Add("Description", activity["TourDescription"].ToString()); newPoint.Properties.Add("Duration", activity["TourDuration"].ToString()); newPoint.Properties.Add("TourType", activity["TourType"].ToString()); foreach (var attr in activity["ATTRIBUTES"].Children().ToList()) { newPoint.Properties.Add(attr["AttributeName"].ToString(), attr["AttributeValue"].ToString()); } } else { newPoint.Title = "Unknown Activity"; newPoint.Id = retval.Points.Count.ToString(); } retval.Points.Add(newPoint); } retval.TotalResults = retval.Points.Count; return retval; }
public GeoJson.PointLayer GetPointLayerByBounds(double neLat, double neLng, double swLat, double swLng, int page = 1, string[] ds = null, string[] tags = null) { //Consumer Key: kVvCwX0ocRhDHbA9LfdLrQ //Consumer Secret: RCJdVyZ5R3pVoc3hzyXIy-0ILQ0 //Token: ZgOH_PB5SkKIOIIeI3_9vYRE5ZNTZiIn //Token Secret: rSn8bgTH44an2XYJTgqQQqcDubs PointLayer layer = new PointLayer(this.DataSource); var options = new Options() { AccessToken = "ZgOH_PB5SkKIOIIeI3_9vYRE5ZNTZiIn", AccessTokenSecret = "rSn8bgTH44an2XYJTgqQQqcDubs", ConsumerKey = "kVvCwX0ocRhDHbA9LfdLrQ", ConsumerSecret = "RCJdVyZ5R3pVoc3hzyXIy-0ILQ0" }; Yelp yelp = new Yelp(options); SearchOptions searchOptions = new SearchOptions() { LocationOptions = new BoundOptions() { sw_latitude = swLat, sw_longitude = swLng, ne_latitude = neLat, ne_longitude = neLng } }; //VectorLocation vLocation = Util.VectorLocationFromBounds(neLat, neLng, swLat, swLng); //LocationOptions location = new LocationOptions(); //CoordinateOptions coords = new CoordinateOptions(); //coords.latitude = vLocation.Latitude; //coords.longitude = vLocation.Longitude; //location.coordinates = coords; //// location.location = coords; //searchOptions.LocationOptions = location; GeneralOptions generalOptions = new GeneralOptions(); //generalOptions.radius_filter = vLocation.Radius; generalOptions.limit = pageSize; if(page > 1) { generalOptions.offset = (page - 1) * pageSize; } searchOptions.GeneralOptions = generalOptions; SearchResults results = yelp.Search(searchOptions).Result; layer.TotalResults = results.total; layer.Page = page; layer.PageCount = layer.TotalResults % pageSize; layer.Points = PointsFromBusinessList(results.businesses); layer.PageSize = pageSize; return layer; }