Пример #1
0
        public async Task <IHttpActionResult> SetLocation(SetLocationBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);


            //if (!result.Succeeded)
            //{
            //    return GetErrorResult(result);
            //}

            return(Ok());
        }
Пример #2
0
        private async void Button_SetLocation(object sender, EventArgs e)
        {
            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            var location = await locator.GetPositionAsync();

            Xamarin.Forms.Maps.Position position = new Xamarin.Forms.Maps.Position(location.Latitude, location.Longitude);
            var position1         = new Position(position.Latitude, position.Longitude);
            var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position1);

            foreach (var address in possibleAddresses)
            {
                txtAddress.Text += address + "\n";
            }

            var location2 = new SetLocationBindingModel
            {
                UserID    = user.UploaderID,
                Latitude  = position.Latitude,
                Longitude = position.Longitude,
            };

            try
            {
                var         json    = JsonConvert.SerializeObject(location2);
                HttpContent content = new StringContent(json);

                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var response = await client.PostAsync(Url1, content);

                if (response.IsSuccessStatusCode)
                {
                    string Message = "Location Set successfully";
                    Toast.MakeText(Android.App.Application.Context, Message, ToastLength.Long).Show();
                }
            }
            catch (Exception)
            {
                string Message = "Location Setting failed";
                Toast.MakeText(Android.App.Application.Context, Message, ToastLength.Long).Show();
            }
        }