private async void setAdress(MarkerOptions pinMarker, GoogleMap.MapClickEventArgs e) { string adress = ""; // Obtengo la posible dirección a partir de la latitud y longitud Geocoder geocoder = new Geocoder(); IEnumerable<string> possibleAdresses = await geocoder.GetAddressesForPositionAsync(new Position(e.Point.Latitude, e.Point.Longitude)); adress = possibleAdresses.ElementAt(0); pinMarker.SetTitle(adress); // Añado el pin al mapa _map.AddMarker(pinMarker).ShowInfoWindow(); // Comparto el punto en App var myApp = App.Current as App; myApp.meetingPoint = new MeetingPoint { Name = adress, Place = new Position(e.Point.Latitude, e.Point.Longitude) }; }
private async void pinTouched (object sender, EventArgs e) { Geocoder geoCoder = new Geocoder (); var addresses = await geoCoder.GetAddressesForPositionAsync (this.Prez.Position); switch (Device.OS) { case TargetPlatform.iOS: Device.OpenUri ( new Uri (string.Format ("http://maps.apple.com/?q={0}", WebUtility.UrlEncode(addresses.FirstOrDefault())))); break; case TargetPlatform.Android: Device.OpenUri ( new Uri (string.Format ("geo:0,0?q={0}", WebUtility.UrlEncode(addresses.FirstOrDefault())))); break; case TargetPlatform.Windows: case TargetPlatform.WinPhone: Device.OpenUri ( new Uri (string.Format ("bingmaps:?where={0}", Uri.EscapeDataString(addresses.FirstOrDefault())))); break; } }
public LamanGeoCoder () { geoCoder = new Geocoder(); var buttAlamBaka = new Button {Text = "Buka koordinat -6.21754,106.6586053." }; buttAlamBaka.Clicked += async (sender, e) => { var posisiAlamBaka = new Position(-6.21754, 106.6586053); var alamatAlamBaka = await geoCoder.GetAddressesForPositionAsync(posisiAlamBaka); foreach (var s in alamatAlamBaka) { label.Text += s + "\n"; } }; var buttHi = new Button {Text = "Buka koordinat -6.1949718,106.8208304."}; buttHi.Clicked += async (sender, e) => { var posisiHI = new Position(-6.1949718, 106.8208304); var alamatHI = await geoCoder.GetAddressesForPositionAsync(posisiHI); foreach (var s in alamatHI) { label.Text += s + "\n"; } }; Content = new StackLayout { Padding = new Thickness(0, 20, 0, 0), Children = {buttHi, buttAlamBaka, label} }; }
// 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; }
public GeocoderPage () { geoCoder = new Geocoder (); var b1 = new Button { Text = "Reverse geocode '37.808, -122.432'" }; b1.Clicked += async (sender, e) => { var fortMasonPosition = new Position (37.8044866, -122.4324132); var possibleAddresses = await geoCoder.GetAddressesForPositionAsync (fortMasonPosition); foreach (var a in possibleAddresses){ l.Text += a + "\n"; } }; var b2 = new Button { Text = "Geocode '394 Pacific Ave'" }; b2.Clicked += async (sender, e) => { var xamarinAddress = "394 Pacific Ave, San Francisco, California"; var approximateLocation = await geoCoder.GetPositionsForAddressAsync (xamarinAddress); foreach (var p in approximateLocation) { l.Text += p.Latitude + ", " + p.Longitude + "\n"; } }; Content = new StackLayout { Padding = new Thickness (0, 20, 0, 0), Children = { b2, b1, l } }; }
public async void AddressesForPosition () { Geocoder.GetAddressesForPositionFuncAsync = GetAddressesForPositionFuncAsync; var geocoder = new Geocoder (); var result = await geocoder.GetAddressesForPositionAsync (new Position (1, 2)); Assert.AreEqual (new String[] { "abc", "def" }, result); }
private async void P_Clicked(object sender, EventArgs e) { Pin p = sender as Pin; Geocoder g = new Geocoder(); foreach(string s in await g.GetAddressesForPositionAsync(p.Position)) { System.Diagnostics.Debug.WriteLine(s); foreach(Position pos in await g.GetPositionsForAddressAsync(s)) { System.Diagnostics.Debug.WriteLine(pos.Latitude + ", " + pos.Longitude); } } }
private async Task LocationChanged(Position p) { intLocCount++; if (intLocCount < 2) { this.Location = p; this.DisplayLocation = String.Format("Lat: {0}, Long: {1}", p.Latitude.ToString(), p.Longitude.ToString()); Geocoder gc = new Geocoder(); this.Address = (await gc.GetAddressesForPositionAsync(p)).First().Replace(Environment.NewLine, ", "); } geo.StopLocationService(); isBusy = false; }
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; } } } }