private void getAddress()
        {
            MapDataTools.GaodeMap gaodeMap = new MapDataTools.GaodeMap();
            int k = 0;

            foreach (DataRow row in dataTable.Rows)
            {
                k++;
                double x = 0;
                double y = 0;
                if (double.TryParse(row["X"].ToString(), out x) && double.TryParse(row["Y"].ToString(), out y))
                {
                    System.Threading.Thread.Sleep(200);
                    string        address = gaodeMap.GetAddressByLocation(x, y, isWgs);
                    MethodInvoker invoker = delegate
                    {
                        DataRow r = myDataTable.NewRow();
                        for (int i = 0; i < row.ItemArray.Length; i++)
                        {
                            r[i] = row[i];
                        }
                        r["Address"] = address;
                        MapDataTools.SVCHelper.AddToSvc(r, this.savePath);
                        progressBar.Value = k * 100 / dataTable.Rows.Count;
                        progressBar.Text  = k.ToString() + "/" + dataTable.Rows.Count.ToString();
                    };
                    if ((!base.IsDisposed) && base.InvokeRequired)
                    {
                        base.Invoke(invoker);
                    }
                    else
                    {
                        invoker();
                    }
                }
            }
            MethodInvoker invokerend = delegate
            {
                progressBar.Value = 100;
                progressBar.Text  = "转换完成";
                btnStart.Enabled  = true;
                btnStop.Enabled   = false;
            };

            if ((!base.IsDisposed) && base.InvokeRequired)
            {
                base.Invoke(invokerend);
            }
            else
            {
                invokerend();
            }
        }
Beispiel #2
0
        private void getLocation()
        {
            MapDataTools.GaodeMap gaodeMap = new MapDataTools.GaodeMap();
            int k = 0;

            foreach (DataRow row in dataTable.Rows)
            {
                k++;
                string address  = row["Address"].ToString();
                string cityName = row["City"].ToString();
                string cityCode = "";
                List <MapDataTools.City> cities = MapDataTools.CityConfig.GetInstance().GetCityByName(cityName);
                if (cities.Count > 0)
                {
                    cityCode = cities[0].gaodeCode;
                }
                if (address != "")
                {
                    MapDataTools.Coord c = gaodeMap.GetLocationByAddress(address, cityCode, isWgs);
                    if (c == null)
                    {
                        continue;
                    }
                    MethodInvoker invoker = delegate
                    {
                        DataRow r = myDataTable.NewRow();
                        for (int i = 0; i < row.ItemArray.Length; i++)
                        {
                            r[i] = row[i];
                        }
                        r["X"] = c.lon;
                        r["Y"] = c.lat;
                        MapDataTools.SVCHelper.AddToSvc(r, this.savePath);
                        progressBar.Value = k * 100 / dataTable.Rows.Count;
                        progressBar.Text  = k.ToString() + "/" + dataTable.Rows.Count.ToString();
                    };
                    if ((!base.IsDisposed) && base.InvokeRequired)
                    {
                        base.Invoke(invoker);
                    }
                    else
                    {
                        invoker();
                    }
                }
            }
            MethodInvoker invokerend = delegate
            {
                progressBar.Value    = 100;
                progressBar.Text     = "转换完成";
                btnStart.Enabled     = true;
                this.btnStop.Enabled = false;
            };

            if ((!base.IsDisposed) && base.InvokeRequired)
            {
                base.Invoke(invokerend);
            }
            else
            {
                invokerend();
            }
        }