private void putPoiInfoIntoVenue(POIWebModel poi, Venue venue, bool putLocation) { if (poi.HasPoiID) { venue.PoiID = poi.PoiID; } if (poi.HasPhone) { venue.PhoneNumber = poi.Phone; } if (poi.HasWebsite) { venue.Website = poi.Website; } if (poi.HasAddress) { venue.Address = poi.Address; } if (poi.HasPoiID) { venue.PoiID = poi.PoiID; } if (putLocation && poi.Location != null) { venue.Latitude = poi.Location.Latitude; venue.Longitude = poi.Location.Longitude; } }
async void createVenue(POIWebModel poi) { this.panelInfo.IsVisible = true; this.panelList.IsVisible = false; this.labelInfo.Text = "Please wait. Registering the venue."; VenueWebModel venue = new VenueWebModel(); venue.Address = poi.Address; venue.Country = ""; venue.IsSnooker = true; venue.Latitude = poi.Location.Latitude; venue.Longitude = poi.Location.Longitude; venue.Name = poi.Name; venue.PhoneNumber = poi.Phone; venue.Website = poi.Website; venue.ID = await App.WebService.CreateNewVenue(venue); if (venue.ID == 0) { this.labelInfo.Text = "Couldn't register the venue. Internet issues? Venue already exists?"; return; } if (this.VenueCreated != null) { this.VenueCreated(this, venue); } }
public async Task <GoogleVerifyResults> VerifyVenuesWithGoogle(List <Venue> venues) { GoogleVerifyResults results = new GoogleVerifyResults(); results.VenuesVerifiedWithGoogle = new List <Venue>(); results.CountErrors = 0; GoogleGeocodingApi geocodingApi = new GoogleGeocodingApi(); GooglePlacesApi placesApi = new GooglePlacesApi(); for (int i = 0; i < venues.Count; ++i) { var venue = venues[i]; geocodingApi.SleepToAvoidGoogleApiThreshold(); // check for the location if not known if (venue.Location == null) { try { var location = await geocodingApi.LocationFromAddress(venue.Address); venue.Latitude = location.Latitude; venue.Longitude = location.Longitude; } catch (Exception) { results.CountErrors++; continue; } } // check with Places API try { // within 250meters var pois = await placesApi.Search(venue.Location, 250, venue.Name); if (pois.Count == 1) { POIWebModel poi = pois[0]; putPoiInfoIntoVenue(poi, venue, false); results.VenuesVerifiedWithGoogle.Add(venue); continue; // all good } if (pois.Count > 1) { continue; // ambigious } // within 20k pois = await placesApi.Search(venue.Location, 20000, venue.Name); if (pois.Count > 0) { POIWebModel poi = null; if (pois.Count == 1) { poi = pois[0]; } else if (pois[0].Name.Contains(venue.Name) || venue.Name.Contains(pois[0].Name)) { poi = pois[0]; } else if (pois[0].Name.Length >= 3 && venue.Name.Length >= 3 && pois[0].Name.Substring(0, 3).ToLower() == venue.Name.Substring(0, 3).ToLower()) { poi = pois[0]; } if (poi != null) { this.putPoiInfoIntoVenue(poi, venue, true); results.VenuesVerifiedWithGoogle.Add(venue); continue; // all good } } } catch (Exception) { results.CountErrors++; continue; } } return(results); }