I want to be able to retrieve the geographical coordinates (latitude and longitude) for a given address. I'm hoping I can do that if I have the full address (street address + city + state + zip).
If it matters, I am using Bing Maps. The skeleton code I've got is this (fullAddress, AddPushpin(), and getGeoCordsForAddress() are the most pertinent parts):
private void btnSave_Click(object sender, EventArgs e)
{
string fullAddress = string.Empty;
if (MissingValues()) return;
mapName = cmbxMapName.SelectedItem.ToString();
locationName = txtbxLocation.Text;
address = txtbxAddress.Text;
city = txtbxCity.Text;
st8 = txtbxSt8.Text;
zip = txtbxZip.Text;
mapDetailNotes = richtxtbxMapNotes.Text;
fullAddress = string.Format("{0} {1} {2} {3}", address, city, st8, zip);
if (InsertIntoCartographerDetail())
{
MessageBox.Show("insert succeeded");
AddPushpin(fullAddress);
ClearControls();
}
else
{
MessageBox.Show("insert failed");
}
}
private void AddPushpin(string fullAddress)
{
GeoCoordinate geoCoord = getGeoCordsForAddress(fullAddress);
Pushpin pin = new Pushpin();
pin.Location = new Location(geoCoord.Latitude, geoCoord.Longitude);
. . .
}
private GeoCoordinate getGeoCordsForAddress(string fullAddress)
{
GeoCoordinate gc = new GeoCoordinate();
. . . // What goes here?
return gc;
}