private void Locate() { if (vm != null) { var position = new XLabs.Platform.Services.Geolocation.Position(); //default position position.Longitude = vm.Longitude; position.Latitude = vm.Latitude; var pin = new Pin { Type = PinType.Place, Position = new Position(vm.Latitude, vm.Longitude), Label = "Accident Location", Address = "" }; map.Circle = new CustomCircle { Position = position, Radius = 800 }; map.Pins.Add(pin); map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(vm.Latitude, vm.Longitude ), Distance.FromMiles(0.9))); } }
private async void Mpr_close(object sender, EventArgs e) { try { XLabs.Platform.Services.Geolocation.Position po = sender as XLabs.Platform.Services.Geolocation.Position; if (po != null) { gpsLb.Text = po.Latitude + "," + po.Longitude; Position pos = new Position(po.Latitude, po.Longitude); ViewModelLocator.PedidoUsuarioViewModel.DetalleDireccion = (await geo.GetAddressesForPositionAsync(pos)).FirstOrDefault(); var _coordinates = new double[2] { po.Latitude, po.Longitude }; ViewModelLocator.PedidoUsuarioViewModel.punto = new ServiceReference1.Point { type = "Point", coordinates = new System.Collections.ObjectModel.ObservableCollection <double>(_coordinates) }; } } catch (Exception ex) { } }
public AccidentLocationPage(ParentViewModel _vm) { InitializeComponent(); parentVm = _vm; InitalizeViewModel(); address.Text = "No Address Yet..."; address.HorizontalOptions = LayoutOptions.CenterAndExpand; latLong.Text = "No Lat/Lng Yet..."; latLong.HorizontalOptions = LayoutOptions.CenterAndExpand; // The root page of your application map = new CustomMap { IsShowingUser = true, /* /* HeightRequest = 250,#1# WidthRequest = 960,*/ VerticalOptions = LayoutOptions.FillAndExpand, HasScrollEnabled = false, HorizontalOptions = LayoutOptions.FillAndExpand }; var startingPosition = new Position(37.79752, -122.40183); map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(37.79752, -122.40183), Distance.FromMiles(0.9))); confirmButton = new Button(); confirmButton.Text = "That's where my accident is!"; confirmButton.Clicked += (sender, args) => { //todo: //update the view model with the new co-ordinates // address and turn off location services. maybe have button to turn them back on _locationConfirmed = true; DialogOpen(); DisplayAlert("Thanks!", address + "", "Dismiss"); App._locationService.StopUpdates(); DialogClosed(); }; confirmButton.HorizontalOptions = LayoutOptions.FillAndExpand; var stack = new StackLayout { Spacing = 0, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; stack.Children.Add(map); stack.Children.Add(address); stack.Children.Add(latLong); /* stack.Children.Add(confirmButton);*/ Content = stack; MessagingCenter.Subscribe<IGetLocation, CrashLocationResult>(this, "addressExists", async (getLocation, s) => { parentVm.Accident.StreetName = s.Address.StreetName; parentVm.Accident.HouseNameOrNumber = s.Address.HouseNameOrNumber; parentVm.Accident.Town = s.Address.Town; parentVm.Accident.Country = s.Address.Country; parentVm.Accident.PostCode = s.Address.PostCode; address.Text = s.AddressAsString; latLong.Text = s.Lat.ToString() + "-" + s.Lng.ToString(); parentVm.Accident.Latitude = s.Lat; parentVm.Accident.Longitude = s.Lng; parentVm.Accident.AccidentDateTime = DateTime.Now; //Send the data we have to the API, create customer there and new customers on device. // await App.CreateCustomerDeviceAndAPIIfNoKey(); await App.CreateAccidentDeviceAndAPIIfNoKey((DateTime)parentVm.Accident.AccidentDateTime); var position = new XLabs.Platform.Services.Geolocation.Position(); //default position position.Longitude = s.Lng; position.Latitude = s.Lat; var pin = new Pin { Type = PinType.Place, Position = new Position(s.Lat, s.Lng), Label = "Accident Location", Address = "" }; map.Circle = new CustomCircle { Position = position, Radius = 800 }; map.Pins.Add(pin); map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(s.Lat, s.Lng ), Distance.FromMiles(0.9))); //save App.Context.AccidentRepository.AddOrUpdate(parentVm.Accident); //update in api if (!_dialogOpen) { if (!_locationConfirmed) { /* await ConfirmLocation(s.AddressAsString);*/ } } }); /* DisplayAlert("Hang tight, we are locating you now!", "Please wait while we search...", "Ok");*/ }