Example #1
0
        static void Main(string[] args)

        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            //System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("uk_UA");

            string address = "Оболонський проспект, 36Д, Київ";



            /*string strUrl = string.Format("http://maps.google.com./maps/api/geocode/json&address={0}&sensor=false", System.Web.HttpUtility.UrlEncode(address));*/

            GoogleLocationService locationService = new GoogleLocationService();
            MapPoint point = locationService.GetLatLongFromAddress(address);

            // витягти адресу з координат (можна )
            //locationService.GetAddressFromLatLang(point.Latitude, point.Longitude);

            System.Console.WriteLine($"{point.Latitude},{point.Longitude}");
            //50.519432,30.5003759

            // витягти адресу з координат (можна )
            AddressData add = locationService.GetAddressFromLatLang(50.519432, 30.5003759);

            System.Console.WriteLine(add.Address);
        }
        public IEnumerable <string> asearch_test(double lon, double lan)
        {
            var address = "منطقة اللاذقية" + "," + "اللاذقية";
            // string s_address = "," + "اللاذقية";
            var locationService = new GoogleLocationService();
            // GoogleMaps.LocationServices.GoogleLocationService r = locationService.GetRegionFromLatLong(lat, lon);
            // LocationServices  r = new GoogleMaps.LocationServices();

            //   r= locationService.GetRegionFromLatLong(lat, lon);
            var g = new GeocodingRequest();

            var address_gps =
                g.Address = address;

            // g.Region = r.Name;
            g.Sensor   = false;
            g.Language = "ar";
            var response = new GeocodingService().GetResponse(g);



            var         point = locationService.GetLatLongFromAddress(address);
            AddressData a     = locationService.GetAddressFromLatLang(lon, lan);
            //  Directions dir=  locationService.GetDirections(point.Latitude, point.Longitude);
            var s = _ClassifyService.search_test(lon.ToString() + "," + lan.ToString());

            //yield return response.Results[0].PlaceId;
            return(s);
            //  yield return locationService.GetAddressFromLatLang(5 , lon).Address;
            // return "s";



            // return _ClassifyService.search_test(town);
        }
Example #3
0
        private void label17_Click(object sender, EventArgs e)
        {
            double lat = 0;
            double lon = 0;

            if (!double.TryParse(latitudePL.Text, out lat))
            {
                MessageBox.Show("Latitude value is wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!double.TryParse(longitudePL.Text, out lon))
            {
                MessageBox.Show("Longitude value is wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                GoogleLocationService locationService = new GoogleLocationService();
                var point = locationService.GetAddressFromLatLang(lat, lon);
                addressPL.Text = point.Address;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #4
0
        /// <summary>
        /// Querys the GoogleMapsAPI for the city name from latitude and longitude
        /// </summary>
        /// <returns></returns>
        private string GetCityFromCords(double lat, double lon, out string country)
        {
            var geoCodingApiKey = _config.GetSection("AppSettings:GeoCodingAPIKey").Value;
            var locationService = new GoogleLocationService(geoCodingApiKey);
            var address         = locationService.GetAddressFromLatLang(lat, lon);

            country = address.Country;
            return(address.City);
        }
Example #5
0
        public static void Main(string[] args)
        {
            AddressData[] addresses = new AddressData[]
            {
                new AddressData // Belgium
                {
                    Address = "Rue du Cornet 6",
                    City    = "VERVIERS",
                    State   = null,
                    Country = "Belgium",
                    Zip     = "B-4800"
                },
                new AddressData
                {
                    Address = "1600 Pennsylvania ave",
                    City    = "Washington",
                    State   = "DC"
                },
                new AddressData
                {
                    Address = "407 N Maple Dr. #1",
                    City    = "Beverly Hills",
                    State   = "CA"
                }
            };

            var gls     = new GoogleLocationService("AIzaSyAzXXP9EpudRef0ac4ggTt4tmhFQ_8fsc4");
            var results = addresses.Select(a =>
            {
                var latlong = gls.GetLatLongFromAddress(a);
                if (latlong == null)
                {
                    return new { Success = false, Forward = a.ToString(), Reverse = "" }
                }
                ;
                var latitude        = latlong.Latitude;
                var longitude       = latlong.Longitude;
                var reversedAddress = gls.GetAddressFromLatLang(latlong.Latitude, latlong.Longitude);
                return(new
                {
                    Success = true,
                    Forward = $"Address {a} is at {latlong.Latitude}, {latlong.Longitude}",
                    Reverse = $"Reversed Address {reversedAddress} from {latlong.Latitude}, {latlong.Longitude}",
                });
            });

            foreach (var result in results)
            {
                if (result == null)
                {
                    continue;
                }
                System.Console.WriteLine($"{result.Success}: {result.Forward}");
                System.Console.WriteLine($"{result.Success}: {result.Reverse}");
            }
            System.Console.ReadLine();
        }
Example #6
0
    public String getUserLocationFromLatLong()
    {
        // convert lat, long to physical address and return it
        String result = service.GetAddressFromLatLang(userLatitude, userLongitude).ToString();

        if (System.String.IsNullOrEmpty(result))
        {
            result = "Lawrence Street Center, Denver, CO, 80204";
        }

        return(result);
    }
Example #7
0
        public MapAddress GetAddressFromLatLng(double lat, double lng)
        {
            var gls         = new GoogleLocationService(_appSettings.GoogleApiKey);
            var addressData = gls.GetAddressFromLatLang(lat, lng);

            return(new MapAddress
            {
                Address = addressData.Address,
                City = addressData.City,
                Country = addressData.Country,
                Zip = addressData.Zip
            });
        }
Example #8
0
        public static void Main(string[] args)
        {
            AddressData[] addresses = new AddressData[]
            {
                new AddressData // Belgium
                {
                    Address = "Rue du Cornet 6",
                    City    = "VERVIERS",
                    State   = null,
                    Country = "Belgium",
                    Zip     = "B-4800"
                },
                new AddressData
                {
                    Address = "1600 Pennsylvania ave",
                    City    = "Washington",
                    State   = "DC"
                },
                new AddressData
                {
                    Address = "407 N Maple Dr. #1",
                    City    = "Beverly Hills",
                    State   = "CA"
                }
            };

            var gls = new GoogleLocationService();

            foreach (var address in addresses)
            {
                try
                {
                    var latlong = gls.GetLatLongFromAddress(address);
                    if (latlong == null)
                    {
                        continue;
                    }
                    var latitude  = latlong.Latitude;
                    var longitude = latlong.Longitude;
                    System.Console.WriteLine("Address ({0}) is at {1},{2}", address, latitude, longitude);
                    var reversedAddress = gls.GetAddressFromLatLang(latitude, longitude);
                    System.Console.WriteLine("Reversed Address from ({1},{2}) is {0}", reversedAddress, latitude, longitude);
                    System.Console.WriteLine("=======================================");
                }
                catch (System.Net.WebException ex)
                {
                    System.Console.WriteLine("Google Maps API Error {0}", ex.Message);
                }
            }
            System.Console.ReadLine();
        }
Example #9
0
        public async Task <IActionResult> Debug()
        {
            if (!await AdminValidate())
            {
                return(Unauthorized("You need to be an admin for that!"));
            }

            var geoCodingApiKey = _config.GetSection("AppSettings:GeoCodingAPIKey").Value;
            var locationService = new GoogleLocationService(geoCodingApiKey);
            var address         = locationService.GetAddressFromLatLang(47.5337201, 21.5813013);

            //_settingsRepo.AddDefaultSettings("john");
            return(Ok(address));
        }
        public static void Main(string[] args)
        {
            AddressData[] addresses = new AddressData[] 
            {
                new AddressData // Belgium
                {
                    Address = "Rue du Cornet 6",
                    City = "VERVIERS",
                    State = null,
                    Country = "Belgium",
                    Zip = "B-4800"
                },
                new AddressData
                {
                    Address = "1600 Pennsylvania ave",
                    City = "Washington",
                    State = "DC"
                },
                new AddressData
                {
                    Address = "407 N Maple Dr. #1",
                    City = "Beverly Hills",
                    State = "CA"
                }
            };

            var gls = new GoogleLocationService();
            foreach (var address in addresses)
            {
                try
                {
                    var latlong = gls.GetLatLongFromAddress(address);
                    var latitude = latlong.Latitude;
                    var longitude = latlong.Longitude;
                    System.Console.WriteLine("Address ({0}) is at {1},{2}", address, latitude, longitude);
                    var reversedAddress = gls.GetAddressFromLatLang(latitude, longitude);
                    System.Console.WriteLine("Reversed Address from ({1},{2}) is {0}", reversedAddress, latitude, longitude);
                    System.Console.WriteLine("=======================================");
                }
                catch(System.Net.WebException ex)
                {
                    System.Console.WriteLine("Google Maps API Error {0}", ex.Message);
                }
                
            }
            System.Console.ReadLine();
        }
Example #11
0
        public static void Main(string[] args)
        {
            AddressData[] addresses = new AddressData[]
            {
                // Resolve from post code only
                new AddressData {
                    Zip = "10025"
                },
                // Non-US
                new AddressData // Belgium
                {
                    Address = "Rue du Cornet 6",
                    City    = "VERVIERS",
                    State   = null,
                    Country = "Belgium",
                    Zip     = "B-4800"
                },
                new AddressData
                {
                    Address = "1600 Pennsylvania ave",
                    City    = "Washington",
                    State   = "DC"
                },
                new AddressData
                {
                    Address = "407 N Maple Dr. #1",
                    City    = "Beverly Hills",
                    State   = "CA"
                }
            };

            // You'll need to acquire your own Google Maps api key (Geolocation API)
            // https://developers.google.com/maps/documentation/javascript/get-api-key
            var gls     = new GoogleLocationService("AIzaSyBKZp9cuEthSeBVTg51R2VYdebIyPIQwv8");
            var results = addresses.AsParallel().Select(a =>
            {
                var latlong = gls.GetLatLongFromAddress(a);
                if (latlong == null)
                {
                    return new { Success = false, Forward = a.ToString(), Reverse = "" }
                }
                ;
                var latitude        = latlong.Latitude;
                var longitude       = latlong.Longitude;
                var reversedAddress = gls.GetAddressFromLatLang(latlong.Latitude, latlong.Longitude);
                return(new
                {
                    Success = true,
                    Forward = $"Address {a} is at {latlong.Latitude}, {latlong.Longitude}",
                    Reverse = $"Reversed Address {reversedAddress} from {latlong.Latitude}, {latlong.Longitude}",
                });
            });

            foreach (var result in results)
            {
                if (result == null)
                {
                    continue;
                }
                System.Console.WriteLine($"{result.Success}: {result.Forward}");
                System.Console.WriteLine($"{result.Success}: {result.Reverse}");
            }
            System.Console.ReadLine();
        }
Example #12
0
 public static AddressData AddressFromLatLong(double latitude, double longitude)
 {
     return(locationService.GetAddressFromLatLang(latitude, longitude));
 }