Exemplo n.º 1
1
        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;
			}
		}
Exemplo n.º 3
0
		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);
		}
Exemplo n.º 4
0
        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}
            };
        }
Exemplo n.º 5
0
      public AccountDetailsViewModel(Account account)
      {
        if (account == null)
        {
          Account = new Models.Account();
          Account.Industry = Account.IndustryTypes[0];
          Account.OpportunityStage = Account.OpportunityStages[0];

          this.Title = "New Account";
        }
        else
        {
          Account = account;
          this.Title = "Account";
        }


        this.Icon = "account.png";

        dataManager = DependencyService.Get<IDataManager>();
        coder = new Geocoder();


        MessagingCenter.Subscribe<Account>(this, "Account", (Account) =>
        {
            IsInitialized = false;
        });

      }
		// 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 CustomerDetailViewModel(Customer customer = null)
        {
            _CapabilityService = DependencyService.Get<ICapabilityService>();

            _Geocoder = new Geocoder();

            if (customer == null)
            {
                _IsNewCustomer = true;
                Customer = new Customer();
            }
            else
            {
                _IsNewCustomer = false;
                Customer = customer;
            }

            Title = _IsNewCustomer ? "New Customer" : _Customer.DisplayLastNameFirst;

            _AddressString = Customer.AddressString;

            SubscribeToSaveCustomerMessages();

            SubscribeToCustomerLocationUpdatedMessages();
        }
Exemplo n.º 8
0
        public MapPage()
        {
            var customMap = new CustomMap
            {
                MapType = MapType.Street,
                WidthRequest = App.ScreenWidth,
                HeightRequest = App.ScreenHeight
            };

            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());
        }
        public AcquaintanceDetailViewModel(Acquaintance acquaintance = null)
        {
            _CapabilityService = DependencyService.Get<ICapabilityService>();

            _Geocoder = new Geocoder();

            if (acquaintance == null)
            {
                _IsNewAcquaintance = true;
                Acquaintance = new Acquaintance();
            }
            else
            {
                _IsNewAcquaintance = false;
                Acquaintance = acquaintance;
            }

			Title = _IsNewAcquaintance ? "New Acquaintance" : _Acquaintance.DisplayLastNameFirst;

            _AddressString = Acquaintance.AddressString;

            SubscribeToSaveAcquaintanceMessages();

            SubscribeToAcquaintanceLocationUpdatedMessages();
        }
Exemplo n.º 10
0
		private async Task FetchData() {
			var apiService = new FatSubsService ();
			var apiResult = await apiService.GetDetailsAsync ();
			if (apiResult != null) {
				Model = apiResult;
				var coder = new Geocoder ();
				var portlandPositions = await coder.GetPositionsForAddressAsync ("Portland, Oregon");
				if (portlandPositions.Any()) {
					Portland = portlandPositions.ElementAt (0);
				}

				var positions = await coder.GetPositionsForAddressAsync (Model.Location.Address);
				foreach (var pos in positions) {
					var location = new Pin () {
						Position = pos,
						Address = Model.Location.Address,
						Type = PinType.Place,
						Label = Model.Location.Name
					};

					if (UpdateMapCommand != null) {
						UpdateMapCommand.Execute (location);
					}
				}
			}

		}
		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 AcquaintanceDetailViewModel(Acquaintance acquaintance)
		{
			_CapabilityService = DependencyService.Get<ICapabilityService>();

			_Geocoder = new Geocoder();

			Acquaintance = acquaintance;

			SubscribeToSaveAcquaintanceMessages();
		}
 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);
         }
     }
 }
Exemplo n.º 14
0
        public Getmap()
        {
            //Map map = new Map();
            InitializeComponent();
            geoCoder = new Xamarin.Forms.Maps.Geocoder();
            //var map = new Xamarin.Forms.Maps.Map(Xamarin.Forms.GoogleMaps.MapSpan.FromCenterAndRadius(new Xamarin.Forms.GoogleMaps.Position(37, -122), Xamarin.Forms.GoogleMaps.Distance.FromKilometers(10)));
            //var map = new Xamarin.Forms.Maps.Map(Xamarin.Forms.Maps.MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(37, -122), Xamarin.Forms.Maps.Distance.FromMiles(10)));
            //var pin = new Pin()
            //{
            //    Position = new Xamarin.Forms.Maps.Position(16.43307340526658, 102.8255601788635),
            //    Label = "Some Pin!"
            //};
            //map.Pins.Add(pin);

            //var cp = new ContentPage
            //{
            //    Content = map,
            //};



            //Pin boardwalkPin = new Pin
            //{
            //    Position = new Xamarin.Forms.Maps.Position(16.43307340526658, 102.8255601788635),
            //    Label = "Boardwalk",
            //    Address = "Santa Cruz",
            //    Type = Xamarin.Forms.Maps.PinType.SavedPin
            //};
            //VisibleRegion = MapSpan.FromCenterAndRadius(
            //    new Xamarin.Forms.GoogleMaps.Position()
            //    )
            //var request = new GeolocationRequest(GeolocationAccuracy.Best, TimeSpan.FromSeconds(6));
            //var location = await Geolocation.GetLocationAsync(request);


            // Map Long clicked
            //map.MapLongClicked += (sender, e) =>
            //{
            //    var lat = e.Position.Latitude.ToString("0.000");
            //    var lng = e.Position.Longitude.ToString("0.000");
            //    this.DisplayAlert("MapLongClicked", $"{lat}/{lng}", "CLOSE");
            //};
            //map.MapClicked += async (sender, e) => {


            //    var lat = e.Point.Latitude;
            //    var longs = e.Point.Longitude;
            //    await this.DisplayAlert("MapLongClicked", $"{lat}/{longs}", "CLOSE");
            //};
        }
Exemplo n.º 15
0
      public ContactDetailsViewModel(Contact contact)
      {
        if(contact == null)
        {
          Contact = new Models.Contact();
          this.Title = "New Contact";
        }
        else
        {
          Contact = contact;
          this.Title = contact.FirstName;
        }

        this.Icon = "contact.png";

        dataManager = DependencyService.Get<IDataManager>();
        //this.navigation = navigation;
        coder = new Geocoder();
      }  //end ctor
Exemplo n.º 16
0
        public CalibrationPage()
        {
            l.Text = "LAT,LONG";
            geoCoder = new Geocoder();
            var btnCalibrate = new Button { Text = "Calibrate" };
            btnCalibrate.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(5, 20, 5, 0),
                HorizontalOptions = LayoutOptions.Fill,
                Children = {
                    l,
                    btnCalibrate
                }
            };
        }
 public LocationSearchPage()
 {
     geoCoder = new Xamarin.Forms.Maps.Geocoder();
     geocode  = new Xamarin.Forms.Maps.Geocoder();
     InitializeComponent();
 }
Exemplo n.º 18
0
        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;
                    }
                }
            }
        }
		public ReverseGeocodePage ()
		{
			InitializeComponent ();
			geoCoder = new Geocoder ();
		}
Exemplo n.º 20
0
        public CustomerMapViewModel(Account account)
        {


            _GeoCoder = new Geocoder();
        }
Exemplo n.º 21
0
		public async void PositionsForAddress () {
			Geocoder.GetPositionsForAddressAsyncFunc = GetPositionsForAddressAsyncFunc	;
			var geocoder = new Geocoder ();
			var result = await geocoder.GetPositionsForAddressAsync ("quux");
			Assert.AreEqual (new Position [] { new Position (1, 2), new Position (3, 4) }, result);
		}
        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;
        }
Exemplo n.º 23
0
 public GeoCodingService()
 {
     _GeoCoder = new Geocoder();
 }
 public GeoCodingViewModel()
 {
     _Geocoder = new Geocoder();
 }