protected override async void OnAppearing() { base.OnAppearing(); if (hasLocationPermission) { if (CrossGeolocator.IsSupported && CrossGeolocator.Current.IsGeolocationAvailable && CrossGeolocator.Current.IsGeolocationEnabled) { locator.PositionChanged += Locator_PositionChanged; await locator.StartListeningAsync(TimeSpan.FromSeconds(0), 50, true); var position = await locator.GetPositionAsync(); var center = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); var span = new Xamarin.Forms.Maps.MapSpan(center, 2, 2); locationsMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude), Distance.FromMiles(1))); //using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation)) //{ // conn.CreateTable<Post>(); // var posts = conn.Table<Post>().ToList(); // DisplayInMap(posts); //} var posts = await Post.Read(); DisplayInMap(posts); } } }
private void MoveToRegion(MapSpan mapSpan) { Xamarin.Forms.Maps.Position center = mapSpan.Center; var region = new MKCoordinateRegion(new CLLocationCoordinate2D(center.Latitude, center.Longitude), new MKCoordinateSpan(mapSpan.LatitudeDegrees, mapSpan.LongitudeDegrees)); Control.SetRegion(region, true); }
// From 11-91 no longer using local SQLite - using Azure cloud db instead // bespoke method to loop through all posts private void DisplayInMap(List <Post> posts) { // throw new NotImplementedException(); // boilerplate foreach (var post in posts) { try { var position = new Xamarin.Forms.Maps.Position(post.Latitude, post.Longitude); // shift map Position to record's lat/lng var pin = new Xamarin.Forms.Maps.Pin() // could have used namespace but this d'illustrate where stuff's from { // initialise the map pin's details / parameters Type = PinType.SavedPin, // type could be SearchResult, Generic &c Position = position, Label = post.VenueName, Address = post.Address }; locationsMap.Pins.Add(pin); } catch (NullReferenceException nre) { } catch (Exception e) { } } }
private void Locator_PositionChanged(object sender, PositionEventArgs e) { var position = e.Position; dialogs.Toast($"{position.Latitude} | {position.Longitude}", TimeSpan.FromSeconds(1)); var location = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); var mapSpan = MapSpan.FromCenterAndRadius(location, Distance.FromMeters(100)); var lastPos = Model.Route.LastOrDefault(); if (lastPos == null || (lastPos != null && Distance.BetweenPositions(location, lastPos).Meters > 5)) { Model.AddPosition(location); viewMap.MapElements.Clear(); var route = new Polyline() { StrokeColor = Color.FromHex("#fc6203"), StrokeWidth = 10 }; foreach (var pos in Model.Route) { route.Geopath.Add(pos); } viewMap.MapElements.Add(route); } viewMap.MoveToRegion(mapSpan); }
public MyMapPage() { InitializeComponent(); var posVancouver = new Xamarin.Forms.Maps.Position(49.25, -123.13); var myPin = new Xamarin.Forms.Maps.Pin() { Label = "Vancouver, BC", Position = posVancouver, Type = PinType.SearchResult //no effect in XM 1.4 }; MyMap.Pins.Add(myPin); myPin.Clicked += (object sender, EventArgs e) => { //not currently working - Xam Forms bug? var pin = sender as Xamarin.Forms.Maps.Pin; if (pin != null) { DisplayAlert("Tapped!", "Pin was tapped.", "OK"); Debug.WriteLine("Pin {0} Clicked!!", pin.Label); } }; //move to location var mapSpan = MapSpan.FromCenterAndRadius(posVancouver, Distance.FromKilometers(2.5)); MyMap.MoveToRegion(mapSpan); }
public void MostrarPosMapa(double Latitud, double Longitud) { base.OnAppearing(); //Posicion en el mapa this.MapaGeoLocal.MoveToRegion( MapSpan.FromCenterAndRadius ( new Xamarin.Forms.Maps.Position(Latitud, Longitud), Distance.FromKilometers(0.5) ) ); var pos = new Xamarin.Forms.Maps.Position(Latitud, Longitud); var pin = new Pin { Type = PinType.Place, Position = pos, Label = "Curso - Xamarin - SIPECOM ONLINE" }; this.MapaGeoLocal.Pins.Add(pin); }
private void DisplayInMap(List <Post> posts) { List <Pin> pins = new List <Pin>(); foreach (var post in posts) { try { var position = new Xamarin.Forms.Maps.Position(post.Latitude, post.Longitude); var pin = new Pin() { Type = PinType.SavedPin, Position = position, Label = post.VenueName, Address = post.Address }; locationsMap.Pins.Add(pin); } catch (NullReferenceException nre) { } catch (Exception ex) { } } }
async Task GetCurrentLocation() { if (UserSettings.UseGPS == "True") { try { var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 20; var position = await locator.GetPositionAsync(timeout : TimeSpan.FromMilliseconds(10000)); CurrentPosition = position; var loc = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); PinCollection.Add(new Pin { Position = loc, Type = PinType.Generic, Label = "You are Here!" }); DisplayMessage = $"You are at {position.Latitude} Latitude and {position.Longitude} Longitude"; } catch (Exception ex) { DisplayMessage = ex.Message.ToString(); } } else { DisplayMessage = "GPS is Disabled"; } }
private void CenterMap(double latitude, double longitude) { var center = new Xamarin.Forms.Maps.Position(latitude, longitude); MapSpan span = new MapSpan(center, 1, 1); locationsMap.MoveToRegion(span); }
private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e) { var center = new Xamarin.Forms.Maps.Position(e.Position.Latitude, e.Position.Longitude); //var span = new Xamarin.Forms.Maps.MapSpan(center, 1, 1); //locationMap.MoveToRegion(span); //zoom differently double zoomLevel = 16; double latlongDegrees = 360 / (Math.Pow(2, zoomLevel)); var span = new Xamarin.Forms.Maps.MapSpan(center, latlongDegrees, latlongDegrees); LocationMap.MoveToRegion(span); var elapsedDistanceNumber = Location.CalculateDistance( ChosenLocation.Latitude, ChosenLocation.Longitude, e.Position.Latitude, e.Position.Longitude, DistanceUnits.Kilometers); //ElapsedDistanceMeters = "Distance moved " + elapsedDistanceNumber * 1000 + " meters"; //var elapsedDistanceMetersDouble = elapsedDistanceNumber * 1000; ElapsedDistanceMeters = elapsedDistanceNumber * 1000; CheckDistanceViolation(); }
private static double MARGIN_OF_ERROR = 10.0; // in m public MapPage() { // map with default centre at NUS var NUSCentre = new Xamarin.Forms.Maps.Position(1.2966, 103.7764); map = new BusMap(MapSpan.FromCenterAndRadius(NUSCentre, Distance.FromKilometers(MEAN_MAP_RADIUS))) { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand }; // add map and slider to stack layout var stack = new StackLayout { Spacing = 0 }; stack.Children.Add(map); Icon = "MapTabIcon.png"; Title = "Map"; Content = stack; // add random buses for testing BusSimulator.DispatchBuses(); // init bus and stop pins UpdatePublicBusPins(); UpdateBusPins(); UpdateStopPins(); }
private void SetMapStartPoint() { var center = new Xamarin.Forms.Maps.Position(ChosenLocation.Latitude, ChosenLocation.Longitude); var span = new Xamarin.Forms.Maps.MapSpan(center, 2, 2); LocationMap.MoveToRegion(span); }
private void drawPins(IEnumerable <VLCMonument> monuments) { //MÉTODP QUE RECIBE COMO PARÁMETRO LOS MONUMENTOS QUE SERÁN DIBUJADOS EN EL MAPA List <CustomPin> listPin = new List <CustomPin>(); //RECORRIDO DE LISTADO Y POR CADA UNO CONVIERTE LAS COORDENADAS Y CREA UN PIN QUE COLOCARÁ EN EL MAPA foreach (var monument in monuments) { UniversalTransverseMercator utm = new UniversalTransverseMercator("S", 30, monument.Coordinates[0], monument.Coordinates[1]); Coordinate c = UniversalTransverseMercator.ConvertUTMtoLatLong(utm); Xamarin.Forms.Maps.Position position = new Xamarin.Forms.Maps.Position(c.Latitude.DecimalDegree, c.Longitude.DecimalDegree); map.MoveToRegion(MapSpan.FromCenterAndRadius(position, Xamarin.Forms.Maps.Distance.FromMiles(.5))); var pin = new CustomPin { Type = PinType.Place, Position = new Xamarin.Forms.Maps.Position(c.Latitude.DecimalDegree, c.Longitude.DecimalDegree), Label = monument.Nombre, Icon = monument.Imagen.Substring(0, monument.Imagen.Length - 4), }; listPin.Add(pin); map.Pins.Add(pin); } map.CustomPins = listPin; }
// Return current location ({city} {state}) of device public async Task <string> GetLocation() { try { // Get Longitude and Latitude of current device location var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; locator.AllowsBackgroundUpdates = true; var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000); var geoCoderPosition = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); // Reverse geocoding var geocoder = new Geocoder(); Xamarin.FormsMaps.Init(); var addresses = await geocoder.GetAddressesForPositionAsync(geoCoderPosition); foreach (var address in addresses) { string addressString = address.ToString(); List <string> addressParse = addressString.Split("\n".ToCharArray()).ToList <string>(); string cityState = Regex.Replace(addressParse[1], @"[\d-]", string.Empty); return(cityState.Trim()); } } catch (Exception ex) { UIAlertView avAlert = new UIAlertView("postion failed", ex.Message, null, "OK", null); avAlert.Show(); } return(null); }
// Return current location ({city} {state}) of device public async Task<string> GetLocation() { try { // Get Longitude and Latitude of current device location var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; locator.AllowsBackgroundUpdates = true; var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000); var geoCoderPosition = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); // Reverse geocoding var geocoder = new Geocoder(); Xamarin.FormsMaps.Init(); var addresses = await geocoder.GetAddressesForPositionAsync(geoCoderPosition); foreach (var address in addresses) { string addressString = address.ToString(); List<string> addressParse = addressString.Split("\n".ToCharArray()).ToList<string>(); string cityState = Regex.Replace(addressParse[1], @"[\d-]", string.Empty); return cityState.Trim(); } } catch (Exception ex) { UIAlertView avAlert = new UIAlertView("postion failed", ex.Message, null, "OK", null); avAlert.Show(); } return null; }
protected override void OnAppearing() { Device.BeginInvokeOnMainThread(async() => { if (_geolocator.IsGeolocationEnabled) { _position = await _geolocator.GetLastKnownLocationAsync(); if (_position == null) { _position = await _geolocator.GetPositionAsync(); } var formsMapPosition = new Xamarin.Forms.Maps.Position(_position.Latitude, _position.Longitude); var mapSpan = MapSpan.FromCenterAndRadius(formsMapPosition, Distance.FromKilometers(1)); _map.MoveToRegion(mapSpan); MyPositionPin = new Pin { Address = "Mi ubicación", Position = formsMapPosition, Type = PinType.Generic, Label = "Mi ubicación" }; _map.Pins.Add(MyPositionPin); } else { await DisplayAlert("Un momento", "Debes activar tu GPS para usar la aplicación.", "OK"); } }); }
public TrackingViewModel(IMasterNavigationService masterNavigationService, IPageService pageService, IPositionService positionService) { //init display public vars UserPosition = new Xamarin.Forms.Maps.Position(); counter = 0; //SetHighlightedRoute(); //for DEMO, init pin at first position //VehiculePositionPins.Add(new Pin() { Position = new Xamarin.Forms.Maps.Position(coordinatesX[0], coordinatesY[0]), Type = PinType.Generic, Label = "Navette autonome" }); VehiculePositionPins.Add(new Pin() { Position = new Xamarin.Forms.Maps.Position(45.378963, -71.927798), Type = PinType.Generic, Label = "Navette autonome" }); //UserPosition = new Xamarin.Forms.Maps.Position(coordinatesX[3], coordinatesY[3]); UserPosition = new Xamarin.Forms.Maps.Position(45.378963, -71.927798); //init private vars _navigationService = masterNavigationService; _pageService = pageService; _positionService = positionService; /* * SetPositionsCommand = new Command(async () => await SetPositions()); * timer = new System.Timers.Timer(); * timer.Interval = 2000; * * timer.Elapsed += OnTimedEvent; * timer.AutoReset = true; * timer.Enabled = true;*/ }
private void MoveMap(Plugin.Geolocator.Abstractions.Position position) { var center = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); //koordinatlari aliyoruz.ekranin merkezinde olacak. var span = new MapSpan(center, 0.1, 0.1); //sayisal degerler haritanin ne kadar uzaktan acilmasi gerektigini belirtir. locationsMap.MoveToRegion(span); //istenilen bolgeye haritanin gitmesini sagliyoruz. }
public KataU() { InitializeComponent(); var mapa = new Map(MapSpan.FromCenterAndRadius(new Position(37.393355, -5.983900), Distance.FromMiles(1))) { VerticalOptions = LayoutOptions.FillAndExpand }; var pFesac = new Position(37.371861, -5.999654); var pcampoFutbol = new Position(37.384217, -5.993467); var pin1 = new Pin { Type = PinType.Place, Position = pFesac, Label = "Fesac" }; var pin2 = new Pin { Type = PinType.Place, Position = pcampoFutbol, Label = "Campo Futbol" }; mapa.Pins.Add(pin1); mapa.Pins.Add(pin2); mapaLayout.Children.Add(mapa); }
public MainPage() { InitializeComponent(); Set.Clicked += async (sender, e) => { double latitude = MyMap.VisibleRegion.Center.Latitude; double longitude = MyMap.VisibleRegion.Center.Longitude; var weather = await weatherService.GetCurrentWeather(latitude, longitude); var position = new Xamarin.Forms.Maps.Position(latitude, longitude); var pin = new Pin { Type = PinType.Generic, Position = position, Label = $"{weather.main.temp}°C", Address = $"{weather.description}", }; MyMap.Pins.Add(pin); }; Cancel.Clicked += (sender, e) => { if (MyMap.Pins.Count > 0) { MyMap.Pins.Remove(MyMap.Pins.Last()); } }; }
private void Locator_PositionChanged(object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e) { var center = new Xamarin.Forms.Maps.Position(e.Position.Latitude, e.Position.Longitude); var span = new Xamarin.Forms.Maps.MapSpan(center, 2, 2); locationsMap.MoveToRegion(span); }
private void MoveMap(Plugin.Geolocator.Abstractions.Position position) { var center = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); var span = new Xamarin.Forms.Maps.MapSpan(center, 1, 1); locationsMap.MoveToRegion(span); }
// this is the old code - protected override void OnAppearing() protected async override void OnAppearing() { base.OnAppearing(); //this is the original file var locator = CrossGeolocator.Current; locator.PositionChanged += Locator_PositionChanged; await locator.StartListeningAsync(new TimeSpan(0), 100); var position = await locator.GetPositionAsync(); var center = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); var span = new Xamarin.Forms.Maps.MapSpan(center, 2, 2); locationsMap.MoveToRegion(span); using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation)) { // these are generics method conn.CreateTable<Post>(),conn.Table<Post>() conn.CreateTable <Post>(); var posts = conn.Table <Post>().ToList(); DisplayInMap(posts); } }
private void MostrarMapa(double Latitud, double Longitud) { base.OnAppearing(); //Posicion en el mapa GeoLocal.MoveToRegion( MapSpan.FromCenterAndRadius ( new Xamarin.Forms.Maps.Position(Latitud, Longitud), Distance.FromKilometers(0.5) )); var pos = new Xamarin.Forms.Maps.Position(Latitud, Longitud); var Pin = new Pin { Type = PinType.Place, Position = pos, Label = "Curso de Xamarin" }; GeoLocal.Pins.Add(Pin); //GeoLocal.Pins.Count > 0 //GeoLocal.Pins.Remove(Pin); }
void SetPinOnMap(Double Latitude, Double Longitude, int severidade) { var position = new Xamarin.Forms.Maps.Position(Latitude, Longitude); // Latitude, Longitude PinType pinType = new PinType(); if (severidade < 2) { pinType = PinType.Place; } else { pinType = PinType.SavedPin; } var pin = new Pin { Type = pinType, Position = position, Label = "Bump", Address = "Endereco do defeito" }; map.Pins.Add(pin); }
protected override async void OnAppearing() { base.OnAppearing(); //if (appMap.IsShowingUser) //{ // this.StartPositioning(); //} this.StartPositioning(); //var notes = await App.Database.GetNotesAsync(); var notes = await App.AzureDb.GetNotesAsync(); foreach (var note in notes) { if (!note.Lat.HasValue || !note.Lng.HasValue) { continue; } var position = new Xamarin.Forms.Maps.Position((double)note.Lat, (double)note.Lng); var pin = new Xamarin.Forms.Maps.Pin() { Type = PinType.SavedPin, Position = position, Label = note.Text, }; appMap.Pins.Add(pin); } }
public async Task <Xamarin.Forms.Maps.Position> GetPosition() { IsBusy = true; Xamarin.Forms.Maps.Position p; try { if (!locator.IsGeolocationAvailable) { p = new Xamarin.Forms.Maps.Position(); } if (!locator.IsGeolocationEnabled) { p = new Xamarin.Forms.Maps.Position(); } var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000); p = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); } catch (Exception ex) { Debug.WriteLine(ex.Message); p = new Xamarin.Forms.Maps.Position(); } IsBusy = false; return(p); }
// Get location via Longitude and Latitude private async void GetLocationBtn_OnClicked(object sender, EventArgs e) { try { // get location var location = CrossGeolocator.Current; location.DesiredAccuracy = 1; // set position var position = await location.GetPositionAsync(TimeSpan.FromSeconds(1)); // assign longitude and latitude double latitude = Convert.ToDouble(position.Latitude); double longitude = Convert.ToDouble(position.Longitude); var center = new Xamarin.Forms.Maps.Position(latitude, longitude); await DisplayAlert("Geolocation", $"Latitude: {latitude} Longitude: {longitude}", "Ok"); // Move Map MapSpan mapSpan = MapSpan.FromCenterAndRadius(center, Distance.FromKilometers(0.444)); map.MoveToRegion(mapSpan); } catch (Exception ex) { await DisplayAlert("Geolocation", $"Something went wrong: {ex}", "Ok"); } }
private void DisplayInMap(List <Post> postList) { try { foreach (var post in postList) { if (!string.IsNullOrEmpty(post.Venue)) { var position = new Position(post.Latitude, post.Longitude); var pin = new Pin() { Type = PinType.SavedPin, Position = position, Address = post.Address, Label = post.Venue, }; locationMap.Pins.Add(pin); } } } catch (Exception ex) { } }
public MainPage() { var pos = new Xamarin.Forms.Maps.Position(-15.8046057, -47.896674); var Span = MapSpan.FromCenterAndRadius(pos, Distance.FromMiles(0.3)); map = new Map(Span) { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand }; // add the slider var slider = new Slider(1, 18, 1); slider.ValueChanged += (sender, e) => { var zoomLevel = e.NewValue; // between 1 and 18 var latlongdegrees = 360 / (Math.Pow(2, zoomLevel)); Debug.WriteLine(zoomLevel + " -> " + latlongdegrees); if (map.VisibleRegion != null) { map.MoveToRegion(new MapSpan(map.VisibleRegion.Center, latlongdegrees, latlongdegrees)); } }; // create map style buttons var street = new Button { Text = "Street" }; var hybrid = new Button { Text = "Hybrid" }; var satellite = new Button { Text = "Satellite" }; street.Clicked += HandleClicked; hybrid.Clicked += HandleClicked; satellite.Clicked += HandleClicked; var segments = new StackLayout { Spacing = 30, HorizontalOptions = LayoutOptions.CenterAndExpand, Orientation = StackOrientation.Horizontal, Children = { street, hybrid, satellite }, }; // if (geoLocator.IsGeolocationAvailable == true) { // geoLocator.PositionChanged // } this.Content = new StackLayout { Children = { map, segments, slider } }; }
private void Button_Clicked_1(object sender, EventArgs e) { info i = new info(); var locator = CrossGeolocator.Current; lat = Latitude.Text.ToString(); lng = Longitude.Text.ToString(); Xamarin.Forms.Maps.Position pos = new Xamarin.Forms.Maps.Position(Convert.ToDouble(lat), Convert.ToDouble(lng)); var pin = new Pin() { Position = new Xamarin.Forms.Maps.Position(pos.Latitude, pos.Longitude), Label = "Your location" }; string url = String.Format(@"https://api.sunrise-sunset.org/json?lat={0}&lng={1}", lat.ToString(), lng.ToString()); var json = new WebClient().DownloadString(url); JObject jo = JObject.Parse(json); i.sunrise = jo["results"]["sunrise"].ToString(); i.sunset = jo["results"]["sunset"].ToString(); i.solarNoon = jo["results"]["solar_noon"].ToString(); i.DayLenght = jo["results"]["day_length"].ToString(); i.CivilTwilightBegin = jo["results"]["civil_twilight_begin"].ToString(); i.CivilTwilightEnd = jo["results"]["civil_twilight_end"].ToString(); i.nautical_twilight_begin = jo["results"]["nautical_twilight_begin"].ToString(); i.nautical_twilight_end = jo["results"]["nautical_twilight_end"].ToString(); i.astronomical_twilight_begin = jo["results"]["astronomical_twilight_begin"].ToString(); i.astronomical_twilight_end = jo["results"]["astronomical_twilight_end"].ToString(); myMap.Pins.Add(pin); myMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(Convert.ToDouble(lat), Convert.ToDouble(lng)), Distance.FromMiles(1))); PositionField.Text = "Latitude: " + lat.ToString() + " Lonngitude: " + lng.ToString(); OutputLabel.Text = "Sunrise: " + i.sunrise + "\n\r" + "Sunset: " + i.sunset + "\n\r" + "Solar noon: " + i.solarNoon + "\n\r" + "Day lenght: " + i.DayLenght + "\n\r" + "Civil twilight begin: " + i.CivilTwilightBegin + "\n\r" + "Civil twilight end: " + i.CivilTwilightEnd + "\n\r" + "Nautical twilight begin: " + i.nautical_twilight_begin + "\n\r" + "Nautical twilight end: " + i.nautical_twilight_end + "\n\r" + "Astronomical twilight begin: " + i.astronomical_twilight_begin + "\n\r" + "Astronomical twilight end: " + i.astronomical_twilight_end; }
public async Task OriginAddress() { try { // Get Current Lattitude And Latitude MyMap.CustomPins = new List <CustomPin>(); var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; // var position = await locator.GetLastKnownLocationAsync(); // Xamarin.Forms.Maps.Position position = new Xamarin.Forms.Maps.Position(location.Latitude, location.Longitude); var position1 = new Xamarin.Forms.Maps.Position(double.Parse(Helpers.Constant.originLatitude), double.Parse(Helpers.Constant.originLongitude)); // Latitude, Longitude MyMap.MoveToRegion(new MapSpan(position1, 1, 1)); var pin = new CustomPin { Pin = new Pin { Type = PinType.Place, Position = position1, Label = "", Id = "Mastercard", Address = "", } }; pin.Id = "Mastercard"; MyMap.CustomPins.Add(pin); MyMap.Pins.Add(pin.Pin); } catch (Exception ex) { ex.ToString(); } }
public async Task<string> ShowMyAdress() { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 5; var position = await locator.GetPositionAsync(timeout: 10000); var pos = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); var locationAddress = (await (new Geocoder()).GetAddressesForPositionAsync(pos)); return locationAddress.First().ToString(); }
private void AddPin(Forecast weather) { var position = new Xamarin.Forms.Maps.Position(Latitude, Longitude); var label = BuildLabel(weather.Temperature, weather.Humidity); CoordinatesAndTemperatureAreAvaliable?.Invoke(this, new PinEventArgs { Type = PinType.Place, Position = position, Label = label, Address = string.Empty }); }
public MainPage() { var pos = new Xamarin.Forms.Maps.Position (-15.8046057, -47.896674); var Span = MapSpan.FromCenterAndRadius (pos, Distance.FromMiles (0.3)); map = new Map (Span){ IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand }; // add the slider var slider = new Slider (1, 18, 1); slider.ValueChanged += (sender, e) => { var zoomLevel = e.NewValue; // between 1 and 18 var latlongdegrees = 360 / (Math.Pow(2, zoomLevel)); Debug.WriteLine(zoomLevel + " -> " + latlongdegrees); if (map.VisibleRegion != null) map.MoveToRegion(new MapSpan (map.VisibleRegion.Center, latlongdegrees, latlongdegrees)); }; // create map style buttons var street = new Button { Text = "Street" }; var hybrid = new Button { Text = "Hybrid" }; var satellite = new Button { Text = "Satellite" }; street.Clicked += HandleClicked; hybrid.Clicked += HandleClicked; satellite.Clicked += HandleClicked; var segments = new StackLayout { Spacing = 30, HorizontalOptions = LayoutOptions.CenterAndExpand, Orientation = StackOrientation.Horizontal, Children = {street, hybrid, satellite}, }; // if (geoLocator.IsGeolocationAvailable == true) { // geoLocator.PositionChanged // } this.Content = new StackLayout { Children = {map, segments, slider} }; }
public async Task<List<string>> GetListado() { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 5; var position = await locator.GetPositionAsync(timeout: 10000); var pos = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); var locationAddress = (await (new Geocoder()).GetAddressesForPositionAsync(pos)); List<string> lista = new List<string>(); foreach (var p in locationAddress) { lista.Add(p.ToString()); } return lista; }
void SetPinOnMap(Double Latitude, Double Longitude, int severidade){ var position = new Xamarin.Forms.Maps.Position(Latitude, Longitude); // Latitude, Longitude PinType pinType = new PinType(); if (severidade < 2) { pinType = PinType.Place; }else{ pinType = PinType.SavedPin; } var pin = new Pin { Type = pinType, Position = position, Label = "Bump", Address = "Endereco do defeito" }; map.Pins.Add(pin); }
void UpdatePosition(XLabs.Platform.Services.Geolocation.Position result) { // Show on map - needs code made to work try { var position = new Xamarin.Forms.Maps.Position(result.Latitude, result.Longitude); Device.BeginInvokeOnMainThread( () => { try { IsBusy = false; // if (result.IsFaulted) // { // PositionStatus = ((GeolocationException)t.Exception.InnerException).Error.ToString(); // } // else if (t.IsCanceled) // { // PositionStatus = "Canceled"; // } //else { position = new Xamarin.Forms.Maps.Position (position.Latitude + .01*counter++, position.Longitude); _map.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(1))); var pin = new Pin { Type = PinType.Place, Position = position, Label = "Current Location" }; _map.Pins.Add(pin); } } catch (Exception e) { if (DEBUG) { var notificator = DependencyService.Get<IToastNotificator> (); var tapped = notificator.Notify (ToastNotificationType.Info, "GeoLocator", "GetPositionAsyncContinueWithError: "+e.InnerException.ToString(), TimeSpan.FromSeconds (3)); } } }); } catch (Exception e) { if (DEBUG) { var notificator = DependencyService.Get<IToastNotificator> (); var tapped = notificator.Notify (ToastNotificationType.Info, "GeoLocator", "GetPositionAsyncContinueWithError: "+e.InnerException.ToString(), TimeSpan.FromSeconds (3)); } } }
private async void GetStarted_OnClicked(object sender, EventArgs args) { l = DateTime.Now; var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 5; var position = await locator.GetPositionAsync(timeout: 10000); var pos1 = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); lstPos.Add(pos1); Gmaps.EPins.Add(new PinExtend { Name = "Origen", Location = pos1, Details = "Direccion de origen" }); l.AddMilliseconds(30000); while (start == true) { var locator2 = CrossGeolocator.Current; locator2.DesiredAccuracy = 5; var position2 = await locator2.GetPositionAsync(timeout: 10000); var pos2 = new Xamarin.Forms.Maps.Position(position2.Latitude, position2.Longitude); //await Gmaps.CreateRoute(pos1, pos2); pos1 = pos2; lstPos.Add(pos1); l.AddMilliseconds(30000); } }
private async void Finish_OnClicked(object sender, EventArgs args) { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 5; var position = await locator.GetPositionAsync(timeout: 10000); var pos1 = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); lstPos.Add(pos1); Gmaps.EPins.Add(new PinExtend { Name = "Destino", Location = pos1, Details = "Direccion de destino" }); }
public MapPage() { var fileCheminEquipement = "Maps.Json.EquipementIleDeFrance.json"; var fileCheminInstallement = "Maps.Json.InstallationIleDeFrance.json"; var assembly = typeof(JsonfileRead).GetTypeInfo().Assembly; Stream stream = assembly.GetManifestResourceStream (fileCheminEquipement); var customMap = new CustomMap { MapType = MapType.Street }; geoCoder = new Geocoder (); var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; locator.GetPositionAsync (timeoutMilliseconds: 10000).ContinueWith (t => { var pin = new CustomPin { Pin = new Pin { Type = PinType.Place, Position = new Xamarin.Forms.Maps.Position (t.Result.Latitude, t.Result.Longitude), Label = "Ma Position", //Address = "394 Pacific Ave, San Francisco CA" }, Name = "Xam", Id = "Xamarin" }; customMap.CustomPins = new List<CustomPin> { pin }; customMap.Pins.Add (pin.Pin); customMap.MoveToRegion (MapSpan.FromCenterAndRadius (new Xamarin.Forms.Maps.Position (t.Result.Latitude, t.Result.Longitude), Distance.FromMiles (0.3))); Content = customMap; }, TaskScheduler.FromCurrentSynchronizationContext()); StreamReader r = new StreamReader (stream); string json = r.ReadToEnd (); JArray array = JArray.Parse (json); foreach (JObject content in array.Children<JObject>()) { foreach (JProperty prop in content.Properties()) { if (prop.Name == "geo_point_2d") { string s = (string)prop.Value; string[] words = s.Split (','); string latitudeString = words [0]; string longitudeString = words [1].TrimStart (); double lat = Convert.ToDouble (latitudeString); double lon = Convert.ToDouble (longitudeString); var position = new Xamarin.Forms.Maps.Position (lat, lon); var possibleAddresses = geoCoder.GetAddressesForPositionAsync (position); var pin = new CustomPin { Pin = new Pin { Type = PinType.Place, Position = position, Label = "" //Address = possibleAddresses.Result.ToString() } }; customMap.CustomPins = new List<CustomPin> { pin }; customMap.Pins.Add (pin.Pin); Content = customMap; } } } }
void AddPin(Place a) { var position = new Xamarin.Forms.Maps.Position(a.Latitude,a.Longitude); var pin = new Pin { Type = PinType.Place, Position = position, Label =a.Name, Address=string.Format("Radius: {0}",a.Radius) }; mapView.Pins.Add(pin); Debug.WriteLine("TTTT"); }