public MapsViewModel() { this._mapCenter = new TK.CustomMap.Position(-33.311836, 26.520642); this._pins = new ObservableCollection <TKCustomMapPin>(); this._circles = new ObservableCollection <TKCircle>(); }
public async void dondeVender() { var compra = new Compra { IdCompra = Settings.IdCompra, }; var response = await ApiServices.InsertarAsync <Compra>(compra, new Uri(Constants.BaseApiAddress), "/api/Compras/GetCompra"); compraresult = JsonConvert.DeserializeObject <Compra>(response.Result.ToString()); var color = new Color(0, 0, 255, 0.3); TK.CustomMap.Position centro = new TK.CustomMap.Position(latitude: compraresult.Latitud.Value, longitude: compraresult.Longitud.Value); var circle = new TKCircle { Radius = 700, Center = centro, Color = color }; TkCircle.Add(circle); VerCompra = true; // CenterSearch = new MapSpan(centro, centro.Latitude, centro.Longitude); CenterSearch = (MapSpan.FromCenterAndRadius((new TK.CustomMap.Position(centro.Latitude, centro.Longitude)), Distance.FromMiles(5))); }
private void OnMapClicked(Position position) { string title = "my location"; var existingPin = Pins.FirstOrDefault(); if (existingPin != null) { title = existingPin.Title; } Pins.Clear(); //TODO: Add PinSelectionMode.Single / Multiple AddPin(position, title); }
public void AddPin(Position position, string title) { TKCustomMapPin pin = new TKCustomMapPin { Position = position, IsDraggable = true, ShowCallout = true, Title = title, }; Pins.Add(pin); }
async void Locator() { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 25; var location = await locator.GetPositionAsync(); var position = new TK.CustomMap.Position(location.Latitude, location.Longitude); await Task.Delay(3000); _mapRegion = TK.CustomMap.MapSpan.FromCenterAndRadius(position, TK.CustomMap.Distance.FromKilometers(2)); MapRegion = TK.CustomMap.MapSpan.FromCenterAndRadius(_mapRegion.Center, TK.CustomMap.Distance.FromKilometers(.3)); // Mapa.MoveToMapRegion((MapSpan.FromCenterAndRadius((position), Distance.FromMiles(.3))), true); //Mapa.MoveToRegion(MapSpan.FromCenterAndRadius((position), Distance.FromMiles(.3))); }
private void MapReady(object sender, EventArgs e) { var position = new TK.CustomMap.Position(Convert.ToDouble(city.Latitude), Convert.ToDouble(city.Longitude)); var pin = new TKCustomMapPin { Image = (this.BindingContext as MasterDetailPageDetailViewModel).WindDirectionImageSource, Position = position, Title = city.Name, Anchor = new Point(0, 0), Subtitle = city.CurrentWeather, IsCalloutClickable = true, ShowCallout = true, }; cityMap.Pins = new List <TKCustomMapPin> { pin }; cityMap.MapRegion = MapSpan.FromCenterAndRadius(position, Distance.FromMiles(1)); }
/* * private void MyMap_MapClicked(object sender, TK.CustomMap.TKGenericEventArgs<TK.CustomMap.Position> e) * { * _pins.Clear(); * //if(MyMap.Pins != null) MyMap.Pins.ToList().Clear(); * var pin = new TKCustomMapPin * { * //Type = TKCustomMapPin.Place, * Position = e.Value, * Title = "Posición Actual" * //Label = "Posición Actual", * }; * * _pins.Add(pin); * // MyMap.Pins = _pins; * * }*/ async private void MyMap_PinDragEnd(object sender, TK.CustomMap.TKGenericEventArgs <TK.CustomMap.TKCustomMapPin> e) { double lat = e.Value.Position.Latitude; double lng = e.Value.Position.Longitude; Xamarin.Forms.Maps.Geocoder geoCoder = new Xamarin.Forms.Maps.Geocoder(); TK.CustomMap.Position position = new TK.CustomMap.Position(lat, lng); var vm = (MainViewModel)BindingContext; vm.Maps.Coordenadas = position.Latitude + "," + position.Longitude; var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude)); vm.Maps.Direccion = ""; foreach (var a in possibleAddresses) { vm.Maps.Direccion += a; break; } }
private async void CreateView() { //var pos = new GeoLocationProvider(); //pos.GetLocation(); //var latlong = pos.GetLatLong(); var currentPostion = new TK.CustomMap.Position(-33.311836, 26.520642); //deafualt location is the Drama Department later this will be changedd to use current location check vars above var mapView = new TKCustomMap(TK.CustomMap.MapSpan.FromCenterAndRadius(currentPostion, TK.CustomMap.Distance.FromKilometers(2))); mapView.IsShowingUser = true; mapView.SetBinding(TKCustomMap.PinsProperty, "Pins"); mapView.SetBinding(TKCustomMap.MapClickedCommandProperty, "MapClickedCommand"); mapView.SetBinding(TKCustomMap.MapLongPressCommandProperty, "MapLongPressCommand"); //mapView.SetBinding(TKCustomMap.MapCenterPropert, "MapCenter"); mapView.SetBinding(TKCustomMap.PinSelectedCommandProperty, "PinSelectedCommand"); mapView.SetBinding(TKCustomMap.SelectedPinProperty, "SelectedPin"); mapView.SetBinding(TKCustomMap.RoutesProperty, "Routes"); mapView.SetBinding(TKCustomMap.PinDragEndCommandProperty, "DragEndCommand"); mapView.SetBinding(TKCustomMap.CirclesProperty, "Circles"); mapView.SetBinding(TKCustomMap.CalloutClickedCommandProperty, "CalloutClickedCommand"); mapView.SetBinding(TKCustomMap.PolylinesProperty, "Lines"); mapView.SetBinding(TKCustomMap.PolygonsProperty, "Polygons"); mapView.SetBinding(TKCustomMap.MapRegionProperty, nameof(currentPostion)); mapView.SetBinding(TKCustomMap.RouteClickedCommandProperty, "RouteClickedCommand"); mapView.SetBinding(TKCustomMap.RouteCalculationFinishedCommandProperty, "RouteCalculationFinishedCommand"); mapView.SetBinding(TKCustomMap.TilesUrlOptionsProperty, "TilesUrlOptions"); mapView.SetBinding(TKCustomMap.MapFunctionsProperty, "MapFunctions"); mapView.IsRegionChangeAnimated = true; this.Content = mapView; //this._baseLayout.Children.Add( // mapView, // Constraint.RelativeToView(autoComplete, (r, v) => v.X), // Constraint.RelativeToView(autoComplete, (r, v) => autoComplete.HeightOfSearchBar), // heightConstraint: Constraint.RelativeToParent((r) => r.Height - autoComplete.HeightOfSearchBar), // widthConstraint: Constraint.RelativeToView(autoComplete, (r, v) => v.Width)); //this._baseLayout.Children.Add( // autoComplete, // Constraint.Constant(0), // Constraint.Constant(0)); }
public BoundList(int geol) { InitializeComponent(); if (Application.Current.Properties["Language"] != null) { Thread.CurrentThread.CurrentCulture = (CultureInfo)Application.Current.Properties["Language"]; } plot = geol; store = new List <DetailsGraph2>(); geo = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(geol).GetTag(); if (((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(geol).GetPolygon() != null) { for (int x = 0; ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(geol).GetPolygon().Count > x; x++) { TK.CustomMap.Position ponit = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(geol).GetPolygon().ElementAt(x); store.Add(new DetailsGraph2 { Lat = ponit.Latitude, Lon = ponit.Longitude }); newpolygon.Add(ponit); } LBound.ItemsSource = store; } }
public void AddPin(double latitude, double longitude, string title) { Position position = new Position(latitude, longitude); AddPin(position, title); }
private async void loadCurrentPosition(bool fromButton) { //if (fromButton) //{ await Task.Delay(1500); //} if (!this.IsVisible) { return; } try { var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); if (status != PermissionStatus.Granted) { if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location)) { await DisplayAlert("Need location", "Gunna need that location", "OK"); } var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location); //Best practice to always check that the key exists if (results.ContainsKey(Permission.Location)) { status = results[Permission.Location]; } } if (status == PermissionStatus.Granted) { CancellationTokenSource ctx = new CancellationTokenSource(); var locator = CrossGeolocator.Current; //CrossGeolocator.Current.PositionChanged += CrossGeolocator_Current_PositionChanged; locator.DesiredAccuracy = 15; if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { var location = await locator.GetPositionAsync(TimeSpan.FromSeconds(10)); TK.CustomMap.Position position = new TK.CustomMap.Position(location.Latitude, location.Longitude); // MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(0.25))); _pins.Clear(); var pin = new TKCustomMapPin { IsVisible = true, IsDraggable = true, //Type = TKCustomMapPin.Place, Position = position, Title = "Posición Actual" //Label = "Posición Actual", }; _pins.Add(pin); if (MyMap.Pins == null) { MyMap.Pins = _pins; } MyMap.MoveToMapRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(0.25))); Xamarin.Forms.Maps.Geocoder geoCoder = new Xamarin.Forms.Maps.Geocoder(); var vm = (MainViewModel)BindingContext; vm.Maps.Coordenadas = position.Latitude + "," + position.Longitude; var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude)); vm.Maps.Direccion = ""; foreach (var a in possibleAddresses) { vm.Maps.Direccion += a; break; } } } else if (status != PermissionStatus.Unknown) { await DisplayAlert("Localización denegada", "No se puede continuar, intentar nuevamente.", "OK"); } } catch (Exception ex) { } }