我在项目中使用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)中写入: “无法加载地址”
答案 0 :(得分:1)
Google Maps要求提供个人密钥,由于制裁,在某些国家(例如伊朗)无法获得该密钥。建议使用Open Street,这是一项完全免费的服务。