private void LoadMapHTML(string address, bool initialLoad = false) { if (string.IsNullOrEmpty(tbAPIKey.Text)) { if (!initialLoad) { tbAPIKey.BackColor = ColourHelper.HexStringToColor("f98a85"); MessageBox.Show("Google API field cannot be empty", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { wbMap.Navigate("about:blank"); try { if (wbMap.Document != null) { wbMap.Document.Write(string.Empty); } } catch { } // do nothing with this wbMap.DocumentText = HtmlHelper.GenerateMapHtml("", tbAPIKey.Text); } } else { tbAPIKey.BackColor = Color.White; List <string> latLong = GetLatLong(address, tbAPIKey.Text); bool postCodeOnly = false; if (latLong[0] == "Fail") { // just use the post code if we can't locate the exact address: address = AddressStringHelper.GetPostCodeFromAddress(address); latLong = GetLatLong(address, tbAPIKey.Text); postCodeOnly = true; } if (latLong[0].Contains("Over Limit")) { lblLatLong.Text = "Latitude / Longitude: " + "Query limit reached"; } else if (latLong[0].Contains("The remote server returned an error") || latLong[0].Contains("instance of an object")) { lblLatLong.Text = "Latitude / Longitude: " + "Server / API key error"; } else { if (latLong[0].Contains("Fail")) { lblLatLong.Text = "Latitude / Longitude: " + "Failed to find coordinates"; } else { if (postCodeOnly) { lblLatLong.Text = "Latitude / Longitude: " + latLong[0] + "\t" + latLong[1] + "\t" + "*PC"; } else { lblLatLong.Text = "Latitude / Longitude: " + latLong[0] + "\t" + latLong[1]; } } } lblLatLong.Visible = true; wbMap.Navigate("about:blank"); try { if (wbMap.Document != null) { wbMap.Document.Write(string.Empty); } } catch { } // do nothing with this wbMap.DocumentText = HtmlHelper.GenerateMapHtml(address, tbAPIKey.Text); } }
private void ThreadWorker() { Thread.CurrentThread.IsBackground = true; string api = tbAPIKey.Text; string[] addresses = Regex.Split(tbAddresses.Text, "\n"); int counter = 1; int noIDCount = 1; SetPreloaderVisible(true); foreach (string address in addresses) { if (counter % 49 == 0) { Thread.Sleep(2000); // 2 seconds } try { string formattedAddrress = address.Replace("\r", ""); string[] parts = Regex.Split(formattedAddrress, "\\["); // No id given if (parts.Length == 1) { parts = new string[] { parts[0], "No ID " + noIDCount + "]" }; noIDCount++; } string formattedAddress = AddressStringHelper.GetFormattedAddress(parts[0]); List <string> latLong = GetLatLong(formattedAddress, api); if (latLong[0] == "Over Limit") { AppendResults("[" + parts[1] + "\t" + "Limited Reached" + "\t"); } else if (latLong[0].Contains("The remote server returned an error") || latLong[0].Contains("instance of an object")) { AppendResults("[" + parts[1] + "\t" + "Server / API Key Error" + "\t"); } else if (latLong[0] == "Fail") { // just use the post code if we can't locate the exact address: latLong = GetLatLong(AddressStringHelper.GetPostCodeFromAddress(formattedAddress), api); // still a fail if (latLong[0] == "Fail") { AppendResults("[" + parts[1] + "\t" + "Fail" + "\t"); } else { AppendResults("[" + parts[1] + "\t" + latLong[0] + "\t" + latLong[1] + "\t" + "- Post Code Only"); } } else { AppendResults("[" + parts[1] + "\t" + latLong[0] + "\t" + latLong[1]); } SetProcessInfo(counter, addresses.Length); if (latLong[0] == "Over Limit" || latLong[0].Contains("The remote server returned an error") || latLong[0].Contains("instance of an object")) { SetEnd(); processThread.Abort(); } } catch { // ignore errorrs } counter++; } SetEnd(); }