コード例 #1
0
        private void GetGeo()
        {
            var en   = new testData();
            var data = en.GetData();

            //    IGeocoder geocoder = new GoogleGeocoder();
            foreach (DataRow row in data.Rows)
            {
                //if (row["Lat"] == DBNull.Value)
                {
                    try
                    {
                        var geo = new GoogleGeocoder()
                        {
                            Language = "VN"
                        }.Geocode(row["AddressVN"].ToString() + ",Việt Nam");
                        if (geo != null && geo.Any())
                        {
                            row["Lat"] = geo.First().Coordinates.Latitude;
                            row["Lng"] = geo.First().Coordinates.Longitude;
                            row.AcceptChanges();
                            en.Update(geo.First().Coordinates.Latitude, geo.First().Coordinates.Longitude,
                                      long.Parse(row["PK_DistrictID"].ToString()));
                        }
                        else
                        {
                            en.Update(0, 0, long.Parse(row["PK_DistrictID"].ToString()));
                        }
                    }
                    catch (Exception)
                    {
                        en.Update(0, 0, long.Parse(row["PK_DistrictID"].ToString()));
                    }
                    //string toaDo = Service_Common.ServiceSoapClient.GetGeobyAddressBA3(row["AddressVN"].ToString());
                    //double lat = 0;
                    //double lng = 0;
                    //if (toaDo != "*" && toaDo != string.Empty)
                    //{
                    //    string[] arrString = toaDo.Split(' ');

                    //    double.TryParse(arrString[0], out lat);
                    //    double.TryParse(arrString[1], out lng);
                    //    en.Update(lat, lng, long.Parse(row["PK_DistrictID"].ToString()));
                    //}
                    //else
                    //{

                    //    en.Update(lat, lng, long.Parse(row["PK_DistrictID"].ToString()));
                    //    //MessageBox.Show("Không tìm thấy tọa độ:" + row["AddressVN"].ToString());
                    //}
                    Thread.Sleep(1000);
                }
            }
        }