/// <summary> /// Get search reuslts response from Azure Maps and convert to point of interest list. /// </summary> /// <returns>List of PointOfInterestModels.</returns> private async Task <List <PointOfInterestModel> > GetPointsOfInterestAsync(string url) { url = string.Concat(url, $"&language={userLocale}&subscription-key={apiKey}"); var response = await httpClient.GetStringAsync(url); var apiResponse = JsonConvert.DeserializeObject <SearchResultSet>(response); var pointOfInterestList = new List <PointOfInterestModel>(); if (apiResponse?.Results != null) { foreach (var searchResult in apiResponse.Results) { var newPointOfInterest = new PointOfInterestModel(searchResult); // If the POI list doesn't already have an item with an identical address, add it to the list if (!pointOfInterestList.Any(poi => poi.Address == newPointOfInterest.Address)) { pointOfInterestList.Add(newPointOfInterest); } } } return(pointOfInterestList); }
public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestModel pointOfInterest) { if (pointOfInterest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var city = CityDataStore.Current.Cities.FirstOrDefault(x => x.Id == cityId); if (city == null) { return(NotFound()); } int id = GetCurrentPointOfInterestId(); var result = new PointOfInterestDto { Id = ++id, Name = pointOfInterest.Name, Description = pointOfInterest.Description }; city.PointofInterest.Add(result); return(CreatedAtAction("GetPointOfInterest", new { cityId = cityId, id = result.Id }, result)); }
public IActionResult GetPointOfInterest(int cityId, int id) { try { if (!_repo.CityExists(cityId)) { return(NotFound()); } PointOfInterest pointOfInterest = _repo.GetPointOfInterestForCity(cityId, id); if (pointOfInterest == null) { return(NotFound()); } PointOfInterestModel pointOfInterestModel = _modelFactory .CreatePointOfInterestModel(pointOfInterest); return(Ok(pointOfInterestModel)); } catch (Exception exception) { _logger.LogCritical($"Exception while getting the point of interest " + $"with the id:{id} for city with the id:{cityId}", exception); return(StatusCode(500, Resources.Http500Generic)); } }
public IActionResult UpdatePointOfInterest(int cityId, int id, [FromBody] PointOfInterestModel pointOfInterest) { if (pointOfInterest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var city = CityDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId); if (city == null) { return(NotFound()); } var pointIfInterestFromStore = city.PointofInterest.FirstOrDefault(p => p.Id == id); if (pointIfInterestFromStore == null) { return(NotFound()); } pointIfInterestFromStore.Description = pointOfInterest.Description; pointIfInterestFromStore.Name = pointOfInterest.Name; return(NoContent()); }
/// <summary> /// Get search reuslts response from Azure Maps and convert to point of interest list. /// </summary> /// <returns>List of PointOfInterestModels.</returns> private async Task <List <PointOfInterestModel> > GetPointsOfInterestAsync(string url) { url = string.Concat(url, $"&language={userLocale}&subscription-key={apiKey}"); var response = await httpClient.GetStringAsync(url); var apiResponse = JsonConvert.DeserializeObject <SearchResultSet>(response); var pointOfInterestList = new List <PointOfInterestModel>(); if (apiResponse != null && apiResponse.Results != null) { // Filter Azure Maps results to Type: POI or Point Address // See https://docs.microsoft.com/en-us/rest/api/maps/search/getsearchaddress#searchaddressresult for more information. var filteredSearchResults = apiResponse.Results.Where(x => x.ResultType.Equals("POI") || x.ResultType.Equals("Point Address")); foreach (var searchResult in filteredSearchResults) { var newPointOfInterest = new PointOfInterestModel(searchResult); // If POI is missing a street, we don't want it shown if (!string.IsNullOrEmpty(newPointOfInterest.Street)) { pointOfInterestList.Add(newPointOfInterest); } } } return(pointOfInterestList); }
protected async Task <Card> GetContainerCard(ITurnContext context, string name, LatLng currentCoordinates, List <PointOfInterestModel> pointOfInterestList, IGeoSpatialService service) { var model = new PointOfInterestModel { CardTitle = PointOfInterestSharedStrings.CARD_TITLE, PointOfInterestImageUrl = await service.GetAllPointOfInterestsImageAsync(currentCoordinates, pointOfInterestList, ImageSize.OverviewWidth, ImageSize.OverviewHeight), Provider = new SortedSet <string> { service.Provider } }; foreach (var poi in pointOfInterestList) { model.Provider.UnionWith(poi.Provider); } model.ProviderDisplayText = model.GenerateProviderDisplayText(); return(new Card { Name = GetDivergedCardName(context, name), Data = model }); }
public async Task <string> GetRouteImageAsync(PointOfInterestModel destination, RouteDirections.Route route) { double maxLongitude = -180; double minLongitude = 180; double maxLatitude = -90; double minLatitude = 90; // TODO or we could use Data in Azure Maps Service to store the whole path var sb = new StringBuilder(); int pointsTotal = route.Legs.Sum(leg => leg.Points.Length); int step = Math.Max(1, pointsTotal / 10); int id = 0; foreach (var leg in route.Legs) { while (true) { if (id >= leg.Points.Length) { id -= leg.Points.Length; break; } AddPoint(leg.Points[id].Longitude, leg.Points[id].Latitude); id += step; } } AddPoint(destination.Geolocation.Longitude, destination.Geolocation.Latitude); double centerLongitude = (maxLongitude + minLongitude) * 0.5; double longitudeDifference = maxLongitude - minLongitude; if (longitudeDifference > 180) { centerLongitude = centerLongitude >= 0 ? centerLongitude - 180 : centerLongitude + 180; longitudeDifference = 180 - longitudeDifference; } double centerLatitude = (maxLatitude + minLatitude) * 0.5; double latitudeDifference = maxLatitude - minLatitude; int pinBuffer = 10; double longitudeZoom = Math.Log((ImageWidth - (2 * pinBuffer)) * 360.0 / 512.0 / longitudeDifference, 2); double latitudeZoom = Math.Log((ImageHeight - (2 * pinBuffer)) * 180.0 / 512.0 / latitudeDifference, 2); int zoom = (int)Math.Min(longitudeZoom, latitudeZoom); string pins = string.Format(CultureInfo.InvariantCulture, RoutePins, PointOfInterestSharedStrings.START, route.Legs[0].Points[0].Longitude, route.Legs[0].Points[0].Latitude, PointOfInterestSharedStrings.END, destination.Geolocation.Longitude, destination.Geolocation.Latitude); return(string.Format(CultureInfo.InvariantCulture, ImageUrlForRoute, zoom, centerLongitude, centerLatitude, pins, sb.ToString()) + "&subscription-key=" + apiKey); void AddPoint(double longitude, double latitude) { sb.Append($"|{longitude} {latitude}"); maxLongitude = Math.Max(maxLongitude, longitude); minLongitude = Math.Min(minLongitude, longitude); maxLatitude = Math.Max(maxLatitude, latitude); minLatitude = Math.Min(minLatitude, latitude); } }
public static Activity CreateOpenDefaultAppReply(Activity activity, PointOfInterestModel destination) { var replyEvent = activity.CreateReply(); replyEvent.Type = ActivityTypes.Event; replyEvent.Name = "OpenDefaultApp"; replyEvent.Value = $"geo:{destination.Geolocation.Latitude},{destination.Geolocation.Longitude}"; return(replyEvent); }
public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointOfInterestModel pointOfInterestModel) { try { if (pointOfInterestModel == null) { return(BadRequest("The passed body could not be parsed into the appropriate object")); } if (pointOfInterestModel.Name == pointOfInterestModel.Description) { ModelState.AddModelError("Description", "The provided description should be different from the name"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } City city = _repo.GetCity(cityId, false); if (city == null) { return(NotFound()); } PointOfInterest pointOfInterest = new PointOfInterest() { Name = pointOfInterestModel.Name, Description = pointOfInterestModel.Description, }; _repo.AddPointOfInterestToCity(cityId, pointOfInterest); if (!_repo.SaveChanges()) { _logger.LogInformation($"Failed to save a new point of interest in the city with the id:{cityId}"); return(StatusCode(500, "A problem happened while saving the new entity")); } return(CreatedAtRoute("GetPointOfInterest", new { cityId = city.Id, id = pointOfInterest.Id, }, _modelFactory.CreatePointOfInterestModel(pointOfInterest))); } catch (Exception exception) { _logger.LogCritical($"Exception while adding a point of interest " + $"to the city with the id:{cityId}", exception); return(StatusCode(500, Resources.Http500Generic)); } }
public async Task <string> GetRouteImageAsync(PointOfInterestModel destination, RouteDirections.Route route, int width = 0, int height = 0) { var latLngs = new List <LatLng>(); // TODO or we could use Data in Azure Maps Service to store the whole path var sb = new StringBuilder(); int pointsTotal = route.Legs.Sum(leg => leg.Points.Length); int step = Math.Max(1, pointsTotal / 10); int id = 0; foreach (var leg in route.Legs) { while (true) { if (id >= leg.Points.Length) { id -= leg.Points.Length; break; } AddPoint(leg.Points[id].Longitude, leg.Points[id].Latitude); id += step; } } AddPoint(destination.Geolocation.Longitude, destination.Geolocation.Latitude); width = width <= 0 ? ImageWidth : width; height = height <= 0 ? ImageHeight : height; (double centerLongitude, double centerLatitude, int zoom) = GetCoveredLocationZoom(latLngs, width, height); string pins = string.Format(CultureInfo.InvariantCulture, RoutePins, PointOfInterestSharedStrings.START, route.Legs[0].Points[0].Longitude, route.Legs[0].Points[0].Latitude, PointOfInterestSharedStrings.END, destination.Geolocation.Longitude, destination.Geolocation.Latitude); var imageUrl = string.Format(CultureInfo.InvariantCulture, ImageUrlForRoute, zoom, centerLongitude, centerLatitude, pins, sb.ToString(), width, height) + "&subscription-key=" + apiKey; if (useDataUriQuality > 0) { imageUrl = await ConvertToDataUri(imageUrl); } return(imageUrl); void AddPoint(double longitude, double latitude) { sb.Append($"|{longitude} {latitude}"); latLngs.Add(new LatLng { Latitude = latitude, Longitude = longitude }); } }
protected SingleDestinationResponse ConvertToResponse(PointOfInterestModel model) { var response = new SingleDestinationResponse(); response.ActionSuccess = true; response.Name = model.Name; response.Latitude = model.Geolocation.Latitude; response.Longitude = model.Geolocation.Longitude; response.Telephone = model.Phone; response.Address = model.Address; return(response); }
/// <summary> /// Returns available image from point of interest. /// </summary> /// <param name="pointOfInterest">The point of interest model.</param> /// <returns>PointOfInterestModel.</returns> public async Task <PointOfInterestModel> GetPointOfInterestDetailsAsync(PointOfInterestModel pointOfInterest) { if (pointOfInterest == null) { throw new ArgumentNullException(nameof(pointOfInterest)); } var pointOfInterestList = await GetVenueAsync( string.Format(CultureInfo.InvariantCulture, GetVenueDetailsUrl, pointOfInterest.Id)); return(pointOfInterestList.FirstOrDefault() ?? pointOfInterest); }
public IActionResult UpdatePointOfInterest(int cityId, int id, [FromBody] PointOfInterestModel pointOfInterestModel) { try { if (pointOfInterestModel == null) { return(BadRequest("The passed body could not be parsed into the appropriate object")); } if (pointOfInterestModel.Name == pointOfInterestModel.Description) { ModelState.AddModelError("Description", "The provided description should be different from the name"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_repo.CityExists(cityId)) { return(NotFound()); } PointOfInterest pointOfInterest = _repo.GetPointOfInterestForCity(cityId, id); if (pointOfInterest == null) { return(NotFound()); } pointOfInterest.Name = pointOfInterestModel.Name; pointOfInterest.Description = pointOfInterestModel.Description; _repo.UpdatePointOfInterest(pointOfInterest); if (!_repo.SaveChanges()) { _logger.LogInformation($"Failed to update a point of interest with " + $"the id:{pointOfInterest.Id} for the city with the id:{cityId}"); return(StatusCode(500, "A problem happened while updating the entity")); } return(NoContent()); } catch (Exception exception) { _logger.LogCritical($"Exception while updating the point of interest " + $"for the city with the id:{cityId}", exception); return(StatusCode(500, Resources.Http500Generic)); } }
/// <summary> /// Get search reuslts response from Azure Maps and convert to point of interest list. /// </summary> /// <returns>List of PointOfInterestModels.</returns> private async Task <List <PointOfInterestModel> > GetPointsOfInterestAsync(string url, string poiType = null, string favoredEntity = null) { url = string.Concat(url, $"&language={userLocale}&subscription-key={apiKey}"); var response = await httpClient.GetStringAsync(url); var apiResponse = JsonConvert.DeserializeObject <SearchResultSet>(response); var pointOfInterestList = new List <PointOfInterestModel>(); if (apiResponse?.Results != null) { if (!string.IsNullOrEmpty(favoredEntity)) { var favoredResult = apiResponse.Results.Where((result) => result.EntityType == favoredEntity).ToList(); if (favoredResult.Count > 0) { apiResponse.Results = favoredResult; } } if (!string.IsNullOrEmpty(poiType)) { if (poiType == GeoSpatialServiceTypes.PoiType.Nearest) { var nearestResult = apiResponse.Results.Aggregate((agg, next) => agg.Distance <= next.Distance ? agg : next); if (nearestResult != null) { apiResponse.Results = new List <SearchResult> { nearestResult }; } } } foreach (var searchResult in apiResponse.Results) { var newPointOfInterest = new PointOfInterestModel(searchResult); // If the POI list doesn't already have an item with an identical address, add it to the list if (!pointOfInterestList.Any(poi => poi.Address == newPointOfInterest.Address)) { pointOfInterestList.Add(newPointOfInterest); } } } return(pointOfInterestList); }
/// <summary> /// Get a static map image URL of the Point of Interest and returns PointOfInterestModel. /// </summary> /// <param name="pointOfInterest">The point of interest model.</param> /// <returns>PointOfInterestModel.</returns> public Task <PointOfInterestModel> GetPointOfInterestDetailsAsync(PointOfInterestModel pointOfInterest) { int zoom = 14; string imageUrl = string.Format( CultureInfo.InvariantCulture, ImageUrlByPoint, pointOfInterest?.Geolocation?.Latitude, pointOfInterest?.Geolocation?.Longitude, zoom) + "&subscription-key=" + apiKey; pointOfInterest.PointOfInterestImageUrl = imageUrl; return(Task.FromResult(pointOfInterest)); }
/// <summary> /// Get a static map image URL of the Point of Interest and returns PointOfInterestModel. /// </summary> /// <param name="pointOfInterest">The point of interest model.</param> /// <returns>PointOfInterestModel.</returns> public Task <PointOfInterestModel> GetPointOfInterestDetailsAsync(PointOfInterestModel pointOfInterest, int width = 0, int height = 0) { string imageUrl = string.Format( CultureInfo.InvariantCulture, ImageUrlByPoint, pointOfInterest?.Geolocation?.Longitude, pointOfInterest?.Geolocation?.Latitude, DefaultZoom, width <= 0 ? ImageWidth : width, height <= 0 ? ImageHeight : height) + "&subscription-key=" + apiKey; pointOfInterest.PointOfInterestImageUrl = imageUrl; return(Task.FromResult(pointOfInterest)); }
/// <summary> /// Gets a request to Foursquare API & convert to PointOfInterestModels. /// </summary> /// <param name="url">The HTTP request URL.</param> /// <returns>A list of PointOfInterestModels.</returns> private async Task <List <PointOfInterestModel> > GetVenueAsync(string url) { url = string.Concat(url, $"&client_id={clientId}&client_secret={clientSecret}&v={apiVersion}"); try { var response = await httpClient.GetStringAsync(url); var apiResponse = JsonConvert.DeserializeObject <VenueResponse>(response); var pointOfInterestList = new List <PointOfInterestModel>(); if (apiResponse?.Response != null) { if (apiResponse.Response.Venue != null) { var venue = apiResponse.Response.Venue; var newPointOfInterest = new PointOfInterestModel(venue); pointOfInterestList.Add(newPointOfInterest); } else if (apiResponse?.Response?.Venues != null) { foreach (var venue in apiResponse.Response.Venues) { var newPointOfInterest = new PointOfInterestModel(venue); pointOfInterestList.Add(newPointOfInterest); } } else if (apiResponse?.Response?.Groups != null) { foreach (var item in apiResponse.Response.Groups.First().Items) { var newPointOfInterest = new PointOfInterestModel(item.Venue); pointOfInterestList.Add(newPointOfInterest); } } } return(pointOfInterestList); } catch (Exception ex) { throw new Exception($"{ex.Message}. failed URL: {url}", ex); } }
private void ImageToDataUri(PointOfInterestModel model) { // TODO set this > 0 (like 75) to convert url links of images to jpeg data uris (e.g. when need transcripts) long useDataUriJpegQuality = 0L; if (useDataUriJpegQuality > 0 && !string.IsNullOrEmpty(model.PointOfInterestImageUrl)) { using (var image = Image.FromStream(httpClient.GetStreamAsync(model.PointOfInterestImageUrl).Result)) { MemoryStream ms = new MemoryStream(); var encoder = ImageCodecInfo.GetImageDecoders().Where(x => x.FormatID == ImageFormat.Jpeg.Guid).FirstOrDefault(); var encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, useDataUriJpegQuality); image.Save(ms, encoder, encoderParameters); model.PointOfInterestImageUrl = $"data:image/jpeg;base64,{Convert.ToBase64String(ms.ToArray())}"; } } }
public static Activity CreateOpenDefaultAppReply(Activity activity, PointOfInterestModel destination, OpenDefaultAppType type) { var replyEvent = activity.CreateReply(); replyEvent.Type = ActivityTypes.Event; replyEvent.Name = "OpenDefaultApp"; var value = new OpenDefaultApp(); switch (type) { case OpenDefaultAppType.Map: value.MapsUri = $"geo:{destination.Geolocation.Latitude},{destination.Geolocation.Longitude}"; break; case OpenDefaultAppType.Telephone: value.TelephoneUri = "tel:" + destination.Phone; break; } replyEvent.Value = value; return(replyEvent); }
/// <summary> /// Get search reuslts response from Azure Maps and convert to point of interest list. /// </summary> /// <returns>List of PointOfInterestModels.</returns> private async Task <List <PointOfInterestModel> > GetPointsOfInterestAsync(string url) { url = string.Concat(url, $"&language={userLocale}&subscription-key={apiKey}"); var response = await httpClient.GetStringAsync(url); var apiResponse = JsonConvert.DeserializeObject <SearchResultSet>(response); var pointOfInterestList = new List <PointOfInterestModel>(); if (apiResponse != null && apiResponse.Results != null) { foreach (var searchResult in apiResponse.Results) { var newPointOfInterest = new PointOfInterestModel(searchResult); pointOfInterestList.Add(newPointOfInterest); } } return(pointOfInterestList); }
/// <summary> /// Get a static map image URL of the Point of Interest and returns PointOfInterestModel. /// </summary> /// <param name="pointOfInterest">The point of interest model.</param> /// <param name="width">The image width.</param> /// <param name="height">The image height.</param> /// <returns>PointOfInterestModel.</returns> public async Task <PointOfInterestModel> GetPointOfInterestDetailsAsync(PointOfInterestModel pointOfInterest, int width = 0, int height = 0) { var pin = $"|{pointOfInterest?.Geolocation?.Longitude} {pointOfInterest?.Geolocation?.Latitude}"; string imageUrl = string.Format( CultureInfo.InvariantCulture, ImageUrlForPoints, pointOfInterest?.Geolocation?.Longitude, pointOfInterest?.Geolocation?.Latitude, DefaultZoom, pin, width <= 0 ? ImageWidth : width, height <= 0 ? ImageHeight : height) + "&subscription-key=" + apiKey; if (useDataUriQuality > 0) { imageUrl = await ConvertToDataUri(imageUrl); } pointOfInterest.PointOfInterestImageUrl = imageUrl; return(pointOfInterest); }
public IActionResult UpdatePointOfInterestPartially(int cityId, int id, [FromBody] JsonPatchDocument <PointOfInterestModel> pointofInterestPatchDocument) { if (pointofInterestPatchDocument == null) { return(BadRequest()); } var city = CityDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId); if (city == null) { return(NotFound()); } var pointOfInterestFromStore = city.PointofInterest.FirstOrDefault(p => p.Id == id); if (pointOfInterestFromStore == null) { return(NotFound()); } var pointOfInterestToPatch = new PointOfInterestModel { Name = pointOfInterestFromStore.Name, Description = pointOfInterestFromStore.Description }; pointofInterestPatchDocument.ApplyTo(pointOfInterestToPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } pointOfInterestFromStore.Name = pointOfInterestToPatch.Name; pointOfInterestFromStore.Description = pointOfInterestToPatch.Description; return(NoContent()); }
public async Task <List <POIResultModel> > GetPointsOfInterests(string latlong) { HttpClient client = new HttpClient(); PointOfInterestModel pointOfInterestModel = new PointOfInterestModel(); HttpResponseMessage poiResponse; HttpResponseMessage poiPlaceIDResponse; POIPlacesModel objPOIPlacesModel; List <POIPlacesModel> objPOIPlacesModelList = new List <POIPlacesModel>(); strPointsOfInterestsAPI = strPointsOfInterestsAPI.Replace("{{latlong}}", latlong); poiResponse = client.GetAsync(strPointsOfInterestsAPI).Result; if (poiResponse.IsSuccessStatusCode) { pointOfInterestModel = await poiResponse.Content.ReadAsAsync <PointOfInterestModel>(); List <Result> objResult = pointOfInterestModel.results; foreach (Result res in objResult) { string strPOIPlacesAPI = "https://maps.googleapis.com/maps/api/place/details/json?placeid={{Placeid}}&key=AIzaSyB1UXBM2YIZBBZbzETM6psPtmM27R4QN0E"; objPOIPlacesModel = new POIPlacesModel(); strPOIPlacesAPI = strPOIPlacesAPI.Replace("{{Placeid}}", res.place_id); poiPlaceIDResponse = client.GetAsync(strPOIPlacesAPI).Result; objPOIPlacesModel = await poiPlaceIDResponse.Content.ReadAsAsync <POIPlacesModel>(); objPOIPlacesModelList.Add(objPOIPlacesModel); } } POIResultModel resultModel; List <POIResultModel> resultModelList = new List <POIResultModel>(); foreach (POIPlacesModel objModel in objPOIPlacesModelList) { resultModel = new POIResultModel(); resultModel.name = objModel.result.name; resultModel.icon = objModel.result.icon; resultModel.website = objModel.result.website; resultModelList.Add(resultModel); } if (resultModelList.Count == 0) { resultModel = new POIResultModel(); resultModel.name = "Mission Peak"; resultModel.icon = "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"; resultModel.website = "http://www.google.com"; resultModelList.Add(resultModel); POIResultModel resultModel1; resultModel1 = new POIResultModel(); resultModel1.name = "Sunol Regional Wilderness"; resultModel1.icon = "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"; resultModel1.website = "http://www.google.com"; resultModelList.Add(resultModel1); POIResultModel resultModel2; resultModel2 = new POIResultModel(); resultModel2.name = "Coyote Hills Regional Park"; resultModel2.icon = "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"; resultModel2.website = "http://www.google.com"; resultModelList.Add(resultModel2); POIResultModel resultModel3; resultModel3 = new POIResultModel(); resultModel3.name = "Aqua Adventure"; resultModel3.icon = "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"; resultModel3.website = "http://www.google.com"; resultModelList.Add(resultModel3); } return(resultModelList); }
/// <summary> /// Gets a request to Foursquare API & convert to PointOfInterestModels. /// </summary> /// <param name="url">The HTTP request URL.</param> /// <param name="poiType">The poi type.</param> /// <returns>A list of PointOfInterestModels.</returns> private async Task <List <PointOfInterestModel> > GetVenueAsync(string url, string poiType = null) { url = string.Concat(url, $"&client_id={clientId}&client_secret={clientSecret}&v={apiVersion}"); try { var response = await httpClient.GetStringAsync(url); var apiResponse = JsonConvert.DeserializeObject <VenueResponse>(response); var pointOfInterestList = new List <PointOfInterestModel>(); if (apiResponse?.Response != null) { if (apiResponse.Response.Venue != null) { var venue = apiResponse.Response.Venue; var newPointOfInterest = new PointOfInterestModel(venue); pointOfInterestList.Add(newPointOfInterest); } else if (apiResponse?.Response?.Venues != null) { if (!string.IsNullOrEmpty(poiType)) { if (poiType == GeoSpatialServiceTypes.PoiType.Nearest) { var nearestResult = apiResponse.Response.Venues.Aggregate((agg, next) => agg.Location.Distance <= next.Location.Distance ? agg : next); if (nearestResult != null) { apiResponse.Response.Venues = new Venue[] { nearestResult }; } } } foreach (var venue in apiResponse.Response.Venues) { var newPointOfInterest = new PointOfInterestModel(venue); pointOfInterestList.Add(newPointOfInterest); } } else if (apiResponse?.Response?.Groups != null) { if (!string.IsNullOrEmpty(poiType)) { if (poiType == GeoSpatialServiceTypes.PoiType.Nearest) { var nearestResult = apiResponse.Response.Groups.First().Items.Aggregate((agg, next) => agg.Venue.Location.Distance <= next.Venue.Location.Distance ? agg : next); if (nearestResult != null) { apiResponse.Response.Groups.First().Items = new Item[] { nearestResult }; } } } foreach (var item in apiResponse.Response.Groups.First().Items) { var newPointOfInterest = new PointOfInterestModel(item.Venue); pointOfInterestList.Add(newPointOfInterest); } } } return(pointOfInterestList); } catch (Exception ex) { throw new Exception($"{ex.Message}. failed URL: {url}", ex); } }
public Task <string> GetRouteImageAsync(PointOfInterestModel destination, RouteDirections.Route route) { throw new NotSupportedException(); }