Reputation: 33
I am using GMap.net library and I get the address, but I get the result I don't want.
example : the address i took out
2QRR+26 Cầu Giấy, Hà Nội
Expected actual address :
108 Nguyễn Phong Sắc, Dịch Vọng, Cầu Giấy, Hà Nội
This is the location information I got on the website google map : https://i.sstatic.net/cqgpw.png
This is my code :
private void gmap_OnMapClick(PointLatLng pointClick, MouseEventArgs e)
{
var address = getAddressFromMap(pointClick);
if (address != null)
{
rtbResultAddressGG.Text = "\nAddress : " + address[0];
}
else
{
MessageBox.Show("Unable to get the address !", "");
}
}
private List<String> getAddressFromMap(PointLatLng point)
{
StringBuilder stringBuilder = new StringBuilder();
List<Placemark> placemarks = null;
var sttCode = GMapProviders.GoogleMap.GetPlacemarks(point, out placemarks);
if (sttCode == GeoCoderStatusCode.OK && placemarks != null)
{
List<String> address = new List<string>();
foreach (var placemark in placemarks)
{
address.Add(placemark.Address);
}
return address;
}
return null;
}
Upvotes: -2
Views: 1147
Reputation: 2977
Have you tried checking other values of your address from getAddressFromMap?From source code of thelibrary you are using, it seems that it is using the reverse Geocoding to get the address of the coordinates you are passing which will return array of results from formatted_address field
var ret = new Placemark(geoResult.results[i].formatted_address);
I tried reverse geocoding the coordinate of the address above and I can see that there's indeed a formatted_address 2QRR+26 Cầu Giấy, Hà Nội
however it is not the first formatted_address returned by the array. You can see it on this https://jsfiddle.net/79v3rqm1/ where I show in the console the returned addresses and the 2QRR+26 Cầu Giấy, Hà Nội
is also included but not the first one.
Upvotes: 0