Exemple #1
0
        private async void OnReverseGeoCodeLocation(object sender, EventArgs e)
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                BindingContext = null;
                var geoService     = new GeoCodingService();
                var reverseResults = await geoService.ReverseGeoCodePosition(vm.Latitude, vm.Longitude);

                vm.Geolocation = reverseResults.FirstOrDefault();

                if (vm.Name == $"{vm.Latitude} / {vm.Longitude}" || vm.Name == null)
                {
                    vm.Name = vm.Geolocation;
                }

                BindingContext = vm;
                // await _dataManager.SaveLocationAsync(vm);
            }
        }
        public async Task <IActionResult> Location(Shopper shopper)
        {
            GeoCodingService geo1 = new GeoCodingService();
            int id = 0;

            _context.Shopper.FindAsync(id);
            string   address  = shopper.ZipCode + shopper.City + shopper.Address + shopper.State;
            Location location = await geo1.GetLocation(address);

            //string shopperAddress = "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=GOOGLE_API_KEY";
            shopper = await geo1.AttachLatAndLong(shopper);

            //if (ModelState.IsValid)
            //{
            //    _context.Shopper.Update(shopper);
            //    await _context.SaveChangesAsync();
            //    return RedirectToAction(nameof(Index));
            //}
            return(View());
        }
Exemple #3
0
        private async void OnGetCurrentLocation(object sender, EventArgs e)
        {
            BindingContext = null;

            //Get Current Location
            var geoService = new GeoCodingService();

            var results = await geoService.GetCurrentLocation();

            vm.Latitude  = results.Latitude;
            vm.Longitude = results.Longitude;
            vm.Altitude  = results.Altitude;

            if (CrossConnectivity.Current.IsConnected)
            {
                //Reverse GeoCode Results
                var reverseResults = await geoService.ReverseGeoCodePosition(results.Latitude, results.Longitude);

                vm.Geolocation = reverseResults.FirstOrDefault();

                if (vm.Name == null)
                {
                    vm.Name = vm.Geolocation;
                }
            }

            if (vm.Name == null && vm.Geolocation != null)
            {
                vm.Name = vm.Geolocation;
            }
            else if (vm.Name == null)
            {
                vm.Name = $"{vm.Latitude} / {vm.Longitude}";
            }

            // await _dataManager.SaveLocationAsync(vm);

            BindingContext = vm;

            SetMap(vm.Latitude, vm.Longitude);
        }