【发布时间】:2021-04-21 11:05:17
【问题描述】:
我希望能够检索给定地址的地理坐标(纬度和经度)。如果我有完整的地址(街道地址 + 城市 + 州 + 邮编),我希望我能做到这一点。
如果重要的话,我正在使用 Bing 地图。我得到的骨架代码是这样的(fullAddress、AddPushpin() 和 getGeoCordsForAddress() 是最相关的部分):
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;
}
【问题讨论】:
-
你可以看看这个库:Generic C# Geocoding API,它允许获取包括坐标在内的地址信息。
-
这能回答你的问题吗? Get Latitude Longitude from an address c#
标签: c# wpf winforms bing-maps geo