public IHttpActionResult GetNearby(int precision, string latitudeFrom, string longitudeFrom) { try { var latitude = double.Parse(latitudeFrom); var longitude = double.Parse(longitudeFrom); var events = _db.Events .Include(i => i.Address.City) .Where(x => x.StartDate >= DateTime.Today) .AsNoTracking().ToList(); var items = (from item in events where GeoLocatorHelper.PlacesAround(latitude, longitude, item.Address.Latitude, item.Address.Longitude, precision) <= precision select item); var result = items.Select(s => new { s.EventId, s.Name, s.Logo, s.Address }); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetNearby(int precision, string latitudeFrom, string longitudeFrom) { try { var latitude = double.Parse(latitudeFrom); var longitude = double.Parse(longitudeFrom); var events = _db.Events.Include(i => i.Address.City).ToList(); var eventsNearby = (from item in events where GeoLocatorHelper.PlacesAround(latitude, longitude, item.Address.Latitude, item.Address.Longitude, precision) <= precision select item).ToList(); var items = (from item in eventsNearby let position = new Position(item.Address.Latitude, item.Address.Longitude) select new LocationVm(item.EventId.ToString(), item.Name, item.Address.FullAddress, PinType.Place, LocationType.Event, position, item.Logo)).ToList(); var historicalSights = _db.HistoricalSights.Include(i => i.Address.City).ToList(); var historicalSightsNearby = (from item in historicalSights where GeoLocatorHelper.PlacesAround(latitude, longitude, item.Address.Latitude, item.Address.Longitude, precision) <= precision select item).ToList(); items.AddRange((from item in historicalSightsNearby let position = new Position(item.Address.Latitude, item.Address.Longitude) select new LocationVm(item.HistoricalSightId.ToString(), item.Name, item.Address.FullAddress, PinType.Place, LocationType.Event, position, item.Logo))); var companies = _db.Companies.Include(i => i.Address.City).ToList(); var companiesNearby = (from item in companies where GeoLocatorHelper.PlacesAround(latitude, longitude, item.Address.Latitude, item.Address.Longitude, precision) <= precision select item).ToList(); items.AddRange((from item in companiesNearby let position = new Position(item.Address.Latitude, item.Address.Longitude) select new LocationVm(item.CompanyId.ToString(), item.Name, item.Address.FullAddress, PinType.Place, LocationType.Event, position, item.Logo))); return(Ok(items)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private async void Button_Click(object sender, RoutedEventArgs e) { count++; await Task.Delay(350); await CoreWindow.GetForCurrentThread().Dispatcher.TryRunAsync(CoreDispatcherPriority.Normal, async delegate { if (count == 0) { return; } if (count == 1) { try { await Task.Delay(10); GeoLocatorHelper.GetUserLocation(); } catch { } } else { try { if (!GeoLocatorHelper.IsLocationBusy) { if (MapViewVM.Compass != null) { MapViewVM.CompassEnabled = !MapViewVM.CompassEnabled; if (MapViewVM.CompassEnabled) { (sender as Button).Content = ""; } else { (sender as Button).Content = ""; } } } } catch (Exception ex) { await new MessageDialog(ex.Message).ShowAsync(); } } count = 0; }); }
private async void RunBTNClick() { count++; await Task.Delay(350); if (count == 0) { return; } if (count == 1) { try { await Task.Delay(10); GeoLocatorHelper.GetUserLocation(); } catch { } } else { try { if (!GeoLocatorHelper.IsLocationBusy) { if (MapViewVM.Compass != null) { MapViewVM.CompassEnabled = !MapViewVM.CompassEnabled; if (MapViewVM.CompassEnabled) { thisbtn.Content = ""; } else { thisbtn.Content = ""; } } } } catch (Exception ex) { await new MessageDialog(ex.Message).ShowAsync(); } } count = 0; }
async void LoadExtendedSplashScreen() { ApplyAcrylicAccent(Grid1); InstallVCD(); try { var res = ApplicationData.Current.LocalSettings.Values["LastUserLocation"].ToString(); var latitude = res.Split(',')[0]; var longitude = res.Split(',')[1]; if (MapViewVM.UserLocation == null) { MapViewVM.UserLocation = new ViewModel.ViewModel() { AttractionName = "My Location" } } ; MapViewVM.UserLocation.Location = new Geopoint(new BasicGeoposition() { Latitude = Convert.ToDouble(latitude), Longitude = Convert.ToDouble(longitude) }); MapViewVM.FastLoadGeoPosition = MapViewVM.UserLocation.Location; RemoveExtendedSplash(); return; } catch { } var geolocator = MapViewVM.GeoLocate; var accessStatus = await Geolocator.RequestAccessAsync(); if (accessStatus == GeolocationAccessStatus.Allowed) { geolocator = new Geolocator { MovementThreshold = 1, ReportInterval = 1, DesiredAccuracyInMeters = 1 }; MapViewVM.GeoLocate = geolocator; GeoLocatorHelper.GetUserLocation(); GeoLocatorHelper.LocationFetched += GeoLocatorHelper_LocationFetched; } RemoveExtendedSplash(); }
public MapViewVM() { LocationFlagVisibility = Visibility.Visible; StepsTitleProviderVisibility = Visibility.Collapsed; if (UserLocation == null) { UserLocation = new ViewModel() { AttractionName = "My Location" } } ; StaticVM = this; LoadPage(); } async void LocateUser() { try { var accessStatus = await Geolocator.RequestAccessAsync(); if (accessStatus == GeolocationAccessStatus.Allowed) { Map = MapView.MapControl; if (FastLoadGeoPosition != null) { if (geolocator == null) { geolocator = new Geolocator() { MovementThreshold = 1, ReportInterval = 1, DesiredAccuracyInMeters = 1 }; GeoLocate = geolocator; } else { UserLocation.Location = FastLoadGeoPosition; Map.Center = FastLoadGeoPosition; await AppCore.Dispatcher.RunAsync(CoreDispatcherPriority.High, async delegate { await Map.TryZoomToAsync(16); }); } // Subscribe to the StatusChanged event to get updates of location status changes. //geolocator.StatusChanged += Geolocator_StatusChanged; // Carry out the operation. GeoLocatorHelper.GetUserLocation(); GeoLocatorHelper.LocationFetched += GeoLocatorHelper_LocationFetched; geolocator.PositionChanged += Geolocator_PositionChanged; await AppCore.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate { var savedplaces = SavedPlacesVM.GetSavedPlaces(); foreach (var item in savedplaces) { Map.MapElements.Add(new MapIcon() { Location = new Geopoint(new BasicGeoposition() { Latitude = item.Latitude, Longitude = item.Longitude }), Title = item.PlaceName }); } }); await Task.Delay(150); LocationFlagVisibility = Visibility.Visible; //if (Map.Is3DSupported) //{ // Map.Style = MapStyle.Aerial3DWithRoads; // MapScene mapScene = MapScene.CreateFromLocationAndRadius(snPoint, 500, 150, 70); // await Map.TrySetSceneAsync(mapScene); //} //var r = await MapLocationFinder.FindLocationsAtAsync(snPoint); //if(r.Locations != null) //{ // var re = r.Locations.FirstOrDefault(); // var rg = RegionInfo.CurrentRegion; // var rg2 = new RegionInfo(re.Address.Country); //} } else { LocationFlagVisibility = Visibility.Collapsed; } } else { LocationFlagVisibility = Visibility.Collapsed; var msg = new MessageDialog(MultilingualHelpToolkit.GetString("StringLocationPrivacy", "Text")); msg.Commands.Add(new UICommand(MultilingualHelpToolkit.GetString("StringOK", "Text"), async delegate { await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location", UriKind.RelativeOrAbsolute)); })); msg.Commands.Add(new UICommand(MultilingualHelpToolkit.GetString("StringCancel", "Text"), delegate { })); await msg.ShowAsync(); Window.Current.Activated += Current_Activated; } } catch { } //try //{ // ApplicationData.Current.LocalSettings.Values["WCReponse"].ToString(); //} //catch //{ // var message = new MessageDialog("windowscentral is not a Microsoft News website that you are looking for. See our reply to WindowsCentral post about WinGo Maps."); // message.Commands.Add(new UICommand("See our response on twitter.", async delegate // { // await Launcher.LaunchUriAsync(new Uri("https://twitter.com/NGameAli/status/1028157663752978432")); // })); // await message.ShowAsync(); // ApplicationData.Current.LocalSettings.Values["WCReponse"] = "windowscentral is not a Microsoft News website that you are looking for"; //} }