示例#1
0
        public Location_(double _Latitude, double _Longitude)
        {
            Latitude  = _Latitude;
            Longitude = _Longitude;

            //need to convert from Latitude and Longitude to Address
            try
            {
                using (var client = new WebClient())
                {
                    var queryString = "http://dev.virtualearth.net/REST/v1/Locations/" + Latitude.ToString() + "," + Longitude.ToString() + "?key=I0VLWblEtzGy2oxBtvf7~JJj7TSmhuiA7hT0hN_W6jw~Ake5bPnub0u2657LhMfe3WiODJ6sfV-05Ugn7CclWhVJej75KU4f4j0XqW_dXvaH";

                    string response = client.DownloadString(queryString);
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
                    using (var es = new MemoryStream(Encoding.Unicode.GetBytes(response)))
                    {
                        var      mapResponse = (ser.ReadObject(es) as Response);
                        Location location    = (Location)mapResponse.ResourceSets.First().Resources.First();
                        Address = location.Address.AddressLine + ", " + location.Address.Locality + ", " + location.Address.CountryRegion;
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("invalid location");
            }
        }
示例#2
0
        public Location_(string _Address)
        {
            Address = _Address;
            //need to convert from Address to Latitude and Longitude
            try
            {
                string url = "http://dev.virtualearth.net/REST/v1/Locations?query=" + _Address + "&key=I0VLWblEtzGy2oxBtvf7~JJj7TSmhuiA7hT0hN_W6jw~Ake5bPnub0u2657LhMfe3WiODJ6sfV-05Ugn7CclWhVJej75KU4f4j0XqW_dXvaH";

                using (var client = new WebClient())
                {
                    string response = client.DownloadString(url);
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
                    using (var es = new MemoryStream(Encoding.Unicode.GetBytes(response)))
                    {
                        var      mapResponse = (ser.ReadObject(es) as Response); //Response is one of the Bing Maps DataContracts
                        Location location    = (Location)mapResponse.ResourceSets.First().Resources.First();

                        Latitude  = location.Point.Coordinates[0];
                        Longitude = location.Point.Coordinates[1];
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("Youre Address is incorrect!");
            }
        }
示例#3
0
        /// <summary>
        /// gets address and finds the goeCoordinate of it
        /// </summary>
        /// <param name="address"></param>
        /// <returns>latitude,longitude</returns>
        public GPSCoordinate Geocode(string address)
        {
            try
            {
                string url = "http://dev.virtualearth.net/REST/v1/Locations?query=" + address + "&key=YOUR_BING_MAP_KEY";

                using (var client = new WebClient())
                {
                    string response = client.DownloadString(url);
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
                    using (var es = new MemoryStream(Encoding.Unicode.GetBytes(response)))
                    {
                        var      mapResponse = (ser.ReadObject(es) as Response); //Response is one of the Bing Maps DataContracts
                        Location location    = (Location)mapResponse.ResourceSets.First().Resources.First();
                        return(new GPSCoordinate()
                        {
                            Latitude = location.Point.Coordinates[0],
                            Longitude = location.Point.Coordinates[1]
                        });
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("Can't find this address");
            }
        }
        /// <summary>
        /// gets address and finds the goeCoordinate of it
        /// </summary>
        /// <param name="address"></param>
        /// <returns>latitude,longitude</returns>
        public GPSCoordinate Geocode(string address)
        {
            try
            {
                string url = "http://dev.virtualearth.net/REST/v1/Locations?query=" + address + "&key=xuQaWbafayipDzIFrQEW~Ipjnd9hhYNDCxbfVKm-nGg~ArAbsa9w-R_uDCNusHl1PmbMRzw6pR1QBwQMwb-_bgsXqr0_mOK09R5Sycrful0K";

                using (var client = new WebClient())
                {
                    string response = client.DownloadString(url);
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
                    using (var es = new MemoryStream(Encoding.Unicode.GetBytes(response)))
                    {
                        var      mapResponse = (ser.ReadObject(es) as Response); //Response is one of the Bing Maps DataContracts
                        Location location    = (Location)mapResponse.ResourceSets.First().Resources.First();
                        return(new GPSCoordinate()
                        {
                            Latitude = location.Point.Coordinates[0],
                            Longitude = location.Point.Coordinates[1]
                        });
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("Can't find this address");
            }
        }
示例#5
0
        /// <summary>
        /// the function gets latitude and longitude and finds the address
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns>Street, City, Country</returns>
        public string ReverseGeocode(double latitude, double longitude)
        {
            try
            {
                using (var client = new WebClient())
                {
                    var queryString = "http://dev.virtualearth.net/REST/v1/Locations/" + latitude.ToString() + "," + longitude.ToString() + "?key=YOUR_BING_MAP_KEY";

                    string response = client.DownloadString(queryString);
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
                    using (var es = new MemoryStream(Encoding.Unicode.GetBytes(response)))
                    {
                        var      mapResponse = (ser.ReadObject(es) as Response);
                        Location location    = (Location)mapResponse.ResourceSets.First().Resources.First();
                        return(location.Address.AddressLine + ", " + location.Address.Locality + ", " + location.Address.CountryRegion);
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("invalid image");
            }
        }
        /// <summary>
        /// the function gets latitude and longitude and finds the address
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns>Street, City, Country</returns>
        public string ReverseGeocode(double latitude, double longitude)
        {
            try
            {
                using (var client = new WebClient())
                {
                    var queryString = "http://dev.virtualearth.net/REST/v1/Locations/" + latitude.ToString() + "," + longitude.ToString() + "?key=xuQaWbafayipDzIFrQEW~Ipjnd9hhYNDCxbfVKm-nGg~ArAbsa9w-R_uDCNusHl1PmbMRzw6pR1QBwQMwb-_bgsXqr0_mOK09R5Sycrful0K";

                    string response = client.DownloadString(queryString);
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
                    using (var es = new MemoryStream(Encoding.Unicode.GetBytes(response)))
                    {
                        var      mapResponse = (ser.ReadObject(es) as Response);
                        Location location    = (Location)mapResponse.ResourceSets.First().Resources.First();
                        return(location.Address.AddressLine + ", " + location.Address.Locality + ", " + location.Address.CountryRegion);
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("invalid image");
            }
        }