Esempio n. 1
0
        private async void AddressButton1_OnClick(object sender, EventArgs e)
        {
            try
            {
                Usertype = FindViewById <TextView>(Resource.Id.Usertype);
                Email    = FindViewById <TextView>(Resource.Id.Email);
                Message  = FindViewById <TextView>(Resource.Id.Message);
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;
                TimeSpan ts       = TimeSpan.FromTicks(10000);
                var      position = await locator.GetPositionAsync(timeout : ts);

                Geocoder        geocoder    = new Geocoder(this);
                IList <Address> addressList =
                    await geocoder.GetFromLocationAsync(position.Latitude, position.Longitude, 10);

                Address address = addressList.FirstOrDefault();
                if (address != null)
                {
                    StringBuilder deviceAddress = new StringBuilder();
                    for (int i = 0; i <= address.MaxAddressLineIndex; i++)
                    {
                        deviceAddress.AppendLine(address.GetAddressLine(i));
                    }
                    _addressText.Text = deviceAddress.ToString();

                    RC          = new RegistrationClass();
                    RM          = new CLocation();
                    RM.Email    = Email.Text;
                    RM.UserType = Usertype.Text;
                    RM.address  = deviceAddress.ToString();
                    RM.Message  = Message.Text;
                    RC.CreateDatabaseLocation();

                    bool b = RC.InsertCLocation(RM);


                    if (b)
                    {
                        FindViewById <TextView>(Resource.Id.Status).Text = "Location Saved!";
                    }
                }
                else
                {
                    _addressText.Text = "Unable to determine the address. Try again in a few minutes.";
                }
            }
            catch (Exception a) {
                Console.Write(a.Message);
            }
        }