예제 #1
0
        private async void FindCoordinate()
        {
            string url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + System.Web.HttpUtility.UrlEncode(tbAddress.Text) + "&key=" + API_KEY;

            // webBrowser1.Navigate(url);
            HttpClient client   = new HttpClient();
            var        response = await client.GetAsync(url);

            string result = await response.Content.ReadAsStringAsync();

            MyObject root      = JsonConvert.DeserializeObject <MyObject>(result);
            double   Latitude  = 0.0;
            double   Longitude = 0.0;

            if (!root.status.Equals("OK"))
            {
                return;
            }

            foreach (var item in root.results)
            {
                Latitude  = item.geometry.location.lat;
                Longitude = item.geometry.location.lng;
                if (Latitude > 0 || Longitude > 0)
                {
                    break;
                }
            }
            tbLat.Text  = Latitude + "";
            tbLong.Text = Longitude + "";
            BtnSearchByAddress.PerformClick();
        }
예제 #2
0
        private async void FindAddress()
        {
            string url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + System.Web.HttpUtility.UrlEncode(tbLat.Text) + "," + System.Web.HttpUtility.UrlEncode(tbLong.Text) + "&key=" + API_KEY;

            // webBrowser1.Navigate(url);
            HttpClient client   = new HttpClient();
            var        response = await client.GetAsync(url);

            string result = await response.Content.ReadAsStringAsync();

            MyObject root = JsonConvert.DeserializeObject <MyObject>(result);

            if (!root.status.Equals("OK"))
            {
                return;
            }
            foreach (var item in root.results)
            {
                if (item.formatted_address.Length > 0)
                {
                    tbAddress.Text = item.formatted_address;
                }
                break;
            }
            BtnSearchByAddress.PerformClick();
        }