Beispiel #1
0
    private string ReverseGeocodePoint(string locationString)
    {
        string results = "";
        string key     = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7";
        ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

        // Set the credentials using a valid Bing Maps key
        reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
        reverseGeocodeRequest.Credentials.ApplicationId = key;

        // Set the point to use to find a matching address
        GeocodeService.Location point = new GeocodeService.Location();
        string[] digits = locationString.Split(',');

        point.Latitude  = double.Parse(digits[0].Trim());
        point.Longitude = double.Parse(digits[1].Trim());

        reverseGeocodeRequest.Location = point;

        // Make the reverse geocode request
        GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        GeocodeResponse      geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

        if (geocodeResponse.Results.Length > 0)
        {
            results = geocodeResponse.Results[0].DisplayName;
        }
        else
        {
            results = "No Results found";
        }

        return(results);
    }
Beispiel #2
0
        private string ReverseGeocodePoint(string locationString)
        {
            string results = "";
            string key     = "Am_qwaGQRh4tOT1wCX_lWd2EzqKl1_PuXjX9nuMQZFWehKYgcXqT99avIJhvAGmx";
            ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
            reverseGeocodeRequest.Credentials.ApplicationId = key;

            // Set the point to use to find a matching address
            GeocodeService.Location point = new GeocodeService.Location();
            string[] digits = locationString.Split(',');

            if (digits.Length == 2 &&
                digits[0].Length > 0 && digits[1].Length > 0)
            {
                point.Latitude  = double.Parse(digits[0].Trim());
                point.Longitude = double.Parse(digits[1].Trim());

                reverseGeocodeRequest.Location = point;

                // Make the reverse geocode request
                GeocodeServiceClient geocodeService  = new GeocodeServiceClient();
                GeocodeResponse      geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

                if (geocodeResponse.Results.Length > 0)
                {
                    results = geocodeResponse.Results[0].DisplayName;
                }
                else
                {
                    results = "Location data not available";
                }

                return(results);
            }
            else
            {
                return("Location data not available");
            }
        }
Beispiel #3
0
        public string GeocodeReverseLookup(string latLong)
        {
            var bingMapApiKey = ConfigurationManager.AppSettings["BingMapCredentials"];
            var point = new Location();
            var latLongValue = latLong.Split(',');
            point.Latitude = double.Parse(latLongValue[0].Trim());
            point.Longitude = double.Parse(latLongValue[1].Trim());

            var reverseGeocodeRequest = new ReverseGeocodeRequest
                {
                    Credentials = new Credentials { ApplicationId = bingMapApiKey },
                    Location = point
                };

            var geocodeService = new GeocodeServiceClient();
            var geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

            if(geocodeResponse.Results.Length > 0)
            {
                    return geocodeResponse.Results[0].DisplayName;
            }

            return null;
        }
Beispiel #4
0
        public string ReverseGeocodePoint(string locationString)
        {
            string results = "";

            ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
            reverseGeocodeRequest.Credentials.ApplicationId = key;

            // Set the point to use to find a matching address
            GeocodeService.Location point = new GeocodeService.Location();
            string[] digits = locationString.Split(',');

            point.Latitude = double.Parse(digits[0].Trim());
            point.Longitude = double.Parse(digits[1].Trim());

            reverseGeocodeRequest.Location = point;

            // Make the reverse geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient();
            GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

            if (geocodeResponse.Results.Length > 0)
                results = geocodeResponse.Results[0].DisplayName;
            else
                results = "No Results found";

            return results;
        }
        public string ReverseGeocodePoint( string locationString )
        {
            try
            {
                string results = "";
                string key = "AplxUm9o3hkw6qCXBbp61H7HYlDrz-qz8ldgKLJ8Udjd8MFNJAfxxy2IWrfd4bw8";
                ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
                reverseGeocodeRequest.Credentials.ApplicationId = key;

                // Set the point to use to find a matching address
                GeocodeService.Location point = new GeocodeService.Location();
                string[] digits = locationString.Split(',');

                point.Latitude = double.Parse(digits[0].Trim());
                point.Longitude = double.Parse(digits[1].Trim());

                reverseGeocodeRequest.Location = point;

                // Make the reverse geocode request
                GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

                if (geocodeResponse.Results.Length > 0)
                    results = geocodeResponse.Results[0].DisplayName;
                else
                    results = "No Results found";

                return results;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }
    private string ReverseGeocodePoint(string locationString)
    {
        string results = "";
        string key = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7";
        ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

        // Set the credentials using a valid Bing Maps key
        reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
        reverseGeocodeRequest.Credentials.ApplicationId = key;

        // Set the point to use to find a matching address
        GeocodeService.Location point = new GeocodeService.Location();
        string[] digits = locationString.Split(',');

        point.Latitude = double.Parse(digits[0].Trim());
        point.Longitude = double.Parse(digits[1].Trim());

        reverseGeocodeRequest.Location = point;

        // Make the reverse geocode request
        GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);

        if (geocodeResponse.Results.Length > 0)
            results = geocodeResponse.Results[0].DisplayName;
        else
            results = "No Results found";

        return results;
    }
        private void RetrieveFormatedAddressFromBing(double lat, double lng)
        {
            string results = string.Empty;
            try
            {
                ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

                // Set the credentials using a valid Bing Maps key
                reverseGeocodeRequest.Credentials = new BingMapsGeocode.Credentials();
                reverseGeocodeRequest.Credentials.ApplicationId = "Agc9SoSDINTGiryq7Ns1ddNUS3sQQLXT4eQqXGhkDka9QkMxfudjMs9k5wwPEhDI";

                // Set the point to use to find a matching address
                BingMapsGeocode.Location point = new BingMapsGeocode.Location();
                point.Latitude = lat;
                point.Longitude = lng;

                reverseGeocodeRequest.Location = point;

                // Make the reverse geocode request
                GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);
                if (geocodeResponse.Results != null)
                {
                    Street = geocodeResponse.Results[0].Address.AddressLine;
                    City = geocodeResponse.Results[0].Address.Locality;
                    State = geocodeResponse.Results[0].Address.AdminDistrict;
                    Zip = geocodeResponse.Results[0].Address.PostalCode;
                    Country = geocodeResponse.Results[0].Address.CountryRegion;
                    Debug.WriteLine("{0}, {1}, {2}, {3}, {4}", Street, City, State, Zip, Country);
                }

                //geocodeService.ReverseGeocodeCompleted += new EventHandler<ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted);
                //geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);
            }
            catch (Exception ex)
            {
                throw new MyLoException(ex.Message);
            }
        }