public async Task <ActionResult> Create(Event playDate) { try { var parent = _repo.Parent.GetParent(User.FindFirstValue(ClaimTypes.NameIdentifier)); playDate.ParentId = parent.ParentId; //Geocoding below via maps service GeocodeLocation eventLocationApiCall = await _maps.GetLatLng(playDate.Location.AddressName); playDate.Location.Lat = eventLocationApiCall.results[0].geometry.location.lat; playDate.Location.Lng = eventLocationApiCall.results[0].geometry.location.lng; EventRegistration newEventRegistration = new EventRegistration() { EventId = 0, Event = playDate, ParentId = parent.ParentId, Accepted = true, Role = "Organizer", ConfirmedAttendance = false }; _repo.EventRegistration.Create(newEventRegistration); _repo.Save(); return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// Initializes a new instance of the <see cref="ShopView"/> class. /// </summary> /// <param name="shop">The shop.</param> /// <param name="location">The location.</param> /// <param name="style">The style.</param> public ShopView(Shop shop, GeocodeLocation location, Style style) { this.Shop = shop; this.Pin = new CustomPushPin(location.Location); Pin.Pin.Style = style; ToolTipService.SetToolTip(Pin.Pin, String.Format("{0}\r\n{1}", shop.Name, shop.Address)); }
public async Task <ActionResult> Edit(Event playDate) { try { playDate.Location.LocationId = playDate.EventId; GeocodeLocation eventLocationApiCall = await _maps.GetLatLng(playDate.Location.AddressName); playDate.Location.Lat = eventLocationApiCall.results[0].geometry.location.lat; playDate.Location.Lng = eventLocationApiCall.results[0].geometry.location.lng; _repo.Event.Update(playDate); _repo.Save(); var registrations = _repo.EventRegistration.FindByCondition(e => e.EventId == playDate.EventId).Include("Parent"); foreach (EventRegistration registration in registrations) { _email.EditEvent(registration.Parent, playDate); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
/// <summary> /// Handles the Loaded event of the myMap control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private async void myMap_Loaded(object sender, RoutedEventArgs e) { try { this.MyMap = (Map)sender; Geolocator geolocator = new Geolocator(); //used to obtain user location Geoposition position = await geolocator.GetGeopositionAsync(); double latitude = position.Coordinate.Point.Position.Latitude; double longitude = position.Coordinate.Point.Position.Longitude; Location location = new Location(latitude, longitude); SearchManager searchManager = MyMap.SearchManager; ReverseGeocodeRequestOptions requestOptions = new ReverseGeocodeRequestOptions(location); LocationDataResponse response; do { response = await searchManager.ReverseGeocodeAsync(requestOptions); } while (response.LocationData.Count == 0 || response.LocationData == null); GeocodeLocation currentLocation = response.LocationData[0]; //place a PushPin at the right place (user) CustomPushPin userPin = new CustomPushPin(location); userPin.Pin.Style = this.Resources["PushPinStyle"] as Style; //create the associated toolTip ToolTipService.SetToolTip(userPin.Pin, "Vous"); MyMap.Children.Add(userPin.Pin); MyMap.ZoomLevel = 12; MyMap.Center = location; //used to retrieve shops PagesJaunesShopRetriever retriever = new PagesJaunesShopRetriever(); bool nothing = await retriever.GetShops(currentLocation.Address.Locality, this.Model); this.shopsViewSource.Source = this.Model.Shops; this.ShopViews = new List <ShopView>(); //used to display shops this.ShopViews = await this.createShopViews(this.Model.Shops, searchManager); foreach (ShopView shopView in this.ShopViews) { this.MyMap.Children.Add(shopView.Pin.Pin); } } catch (Exception ex) { } }
public async Task <GeocodeLocation> GetLatLng(string address) { string url = $"https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={APIKeys.GoogleApi}"; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(url); string jsonResult = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { GeocodeLocation custLocationData = JsonConvert.DeserializeObject <GeocodeLocation>(jsonResult); return(custLocationData); } else { return(new GeocodeLocation()); } }
public async Task <ActionResult> Create(Parent parent) { try { parent.IdentityUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); GeocodeLocation locationData = await _maps.GetLatLng(parent.LocationZip.ToString()); parent.Lat = locationData.results[0].geometry.location.lat; parent.Lng = locationData.results[0].geometry.location.lng; _repo.Parent.Create(parent); _repo.Save(); return(RedirectToAction("Index")); } catch { return(View()); } }
private void SearchPaneQuerySubmitted( SearchPane sender, SearchPaneQuerySubmittedEventArgs args) { GeocodeLocation geoCodeLocation = _searchResponse.LocationData .FirstOrDefault(locationData => locationData.Address.FormattedAddress == args.QueryText) ?? _searchResponse.LocationData.FirstOrDefault(); _lastFocusedMapPin = _focusedMapPin; if (geoCodeLocation != null) { MapPin existedMapPin = _mapPins.FirstOrDefault(mapPin => mapPin.Latitude == geoCodeLocation.Location.Latitude.ToString() && mapPin.Longitude == geoCodeLocation.Location.Longitude.ToString()); if (existedMapPin == null) { MapPin mapPinElement = new MapPin(string.Empty, string.Empty, geoCodeLocation.Location.Latitude.ToString(), geoCodeLocation.Location.Longitude.ToString()); mapPinElement.MapPinTapped += MapPinElementMapPinTapped; MapView.Children.Add(mapPinElement); MapLayer.SetPosition(mapPinElement, geoCodeLocation.Location); MapView.SetView(geoCodeLocation.Location, 15.0f); _focusedMapPin = mapPinElement; } else { Location location = new Location(double.Parse(existedMapPin.Latitude), double.Parse(existedMapPin.Longitude)); MapView.SetView(location, 15.0f); existedMapPin.Focus(); _focusedMapPin = existedMapPin; } DefaultViewModel["Focused"] = true; } DefaultViewModel["Linkable"] = (bool)DefaultViewModel["Focused"] && _focusedMapPin.Marked; DefaultViewModel["Markable"] = (bool)DefaultViewModel["Focused"] && !(bool)DefaultViewModel["Linkable"]; DefaultViewModel["UnMarkable"] = (bool)DefaultViewModel["Linkable"]; }
/// <summary> /// Creates the shop views. /// </summary> /// <param name="shops">The shops.</param> /// <param name="searchManager">The search manager.</param> /// <returns></returns> private async Task <List <ShopView> > createShopViews(List <Shop> shops, SearchManager searchManager) { List <ShopView> shopViews = new List <ShopView>(); //get the location associated to all shops and create their views foreach (Shop shop in shops) { var options = new GeocodeRequestOptions(shop.Address); var response = await searchManager.GeocodeAsync(options); GeocodeLocation shopLocation = null; if (response.LocationData.Count > 0) { shopLocation = response.LocationData[0]; ShopView shopView = new ShopView(shop, shopLocation, this.Resources["PushPinMarketStyle"] as Style); shopViews.Add(shopView); } } return(shopViews); }