如何在 C# 中显示来自 gmap 的地址?
How to show a address from gmap in c#?
我在我的项目中使用了Gmap,我想显示一个地址。
我尝试使用 BingMap、Yahoo、OpenStreet 和 googleMap。但我无法显示地址。
我写了这段代码:
private void gMapControl1_MouseClick(object sender, MouseEventArgs e)
{
PointLatLng myPoint= gMapControl1.FromLocalToLatLng(e.X, e.Y);
// GetAddress is my Method
var addresses = GetAddress(myPoint);
// Display Address
if (addresses != null)
richTextBox1.Text = addresses[0];
else
richTextBox1.Text = "Unable To Load Address";
}
// this is my method
List<string> GetAddress(PointLatLng point)
{
List<Placemark> placemarks = null;
gMapControl1.MapProvider = GMapProviders.OpenStreetMap;
var statusCode = GMapProviders.OpenStreetMap.GetPlacemarks(point, out placemarks);
if (statusCode == GeoCoderStatusCode.G_GEO_SUCCESS && placemarks != null)
{
List<String> addresses = new List<string>();
foreach (var placemark in placemarks)
{
addresses.Add(placemark.Address);
}
return addresses;
}
return null;
}
每次都是在richTextBox(GoogleMapProvider)中写:
"Unable To Load Address"
Google 地图需要提供个人密钥,这在某些国家(例如伊朗)由于制裁而无法获得。推荐使用完全免费的Open Street
我在我的项目中使用了Gmap,我想显示一个地址。
我尝试使用 BingMap、Yahoo、OpenStreet 和 googleMap。但我无法显示地址。 我写了这段代码:
private void gMapControl1_MouseClick(object sender, MouseEventArgs e)
{
PointLatLng myPoint= gMapControl1.FromLocalToLatLng(e.X, e.Y);
// GetAddress is my Method
var addresses = GetAddress(myPoint);
// Display Address
if (addresses != null)
richTextBox1.Text = addresses[0];
else
richTextBox1.Text = "Unable To Load Address";
}
// this is my method
List<string> GetAddress(PointLatLng point)
{
List<Placemark> placemarks = null;
gMapControl1.MapProvider = GMapProviders.OpenStreetMap;
var statusCode = GMapProviders.OpenStreetMap.GetPlacemarks(point, out placemarks);
if (statusCode == GeoCoderStatusCode.G_GEO_SUCCESS && placemarks != null)
{
List<String> addresses = new List<string>();
foreach (var placemark in placemarks)
{
addresses.Add(placemark.Address);
}
return addresses;
}
return null;
}
每次都是在richTextBox(GoogleMapProvider)中写: "Unable To Load Address"
Google 地图需要提供个人密钥,这在某些国家(例如伊朗)由于制裁而无法获得。推荐使用完全免费的Open Street