public VisitedPlace GetNearbyPlace(GeoPosition position, int locationId) { var response = _googleClient.GetNearbyPlaces(position.Latitude, position.Longitude); GPlacesResult selectedResult = null; if (response.IsOk && response.results.Any()) { selectedResult = response.results.FirstOrDefault(r => r.types.Any(t => t == "point_of_interest")); if (selectedResult == null) { selectedResult = response.results.FirstOrDefault(); } } if (selectedResult == null) { Debug.WriteLine($"Could not find location by name for {position.GetDisplay()} "); return(null); } var place = new VisitedPlace() { Where = position.LatLong, LocationId = locationId, PlaceName = selectedResult.name.RemoveDiacritics(), Types = selectedResult.types }; var existing = _placeRepo.VisitedPlaces.FirstOrDefault(p => p.LocationId == place.LocationId && p.PlaceName == place.PlaceName); if (existing != null) { return(existing); } // Handle New place place.Id = _placeRepo.GetNewId(); _placeRepo.VisitedPlaces.Add(place); _placeRepo.Save(); string baseDirectory = @"c:\TripLine\Places\Request\"; Directory.CreateDirectory(baseDirectory); string fpath = baseDirectory + $"{place.Id}_{place.PlaceName}" + ".txt"; using (var writer = new StreamWriter(File.Open(fpath, FileMode.Create, FileAccess.Write))) { writer.WriteLine(response.Serialize()); } Debug.WriteLine($"Found new place {place.PlaceName} at {position.GetDisplay()} :: {place.Types} "); return(place); }