I am beginner in asp.net (c#) But i need to get the utf-8 address from latitude & longitude position So i need to retrieve the address in fa language and i We've added language= fa to String map address. but it retrieved the strange character this is my code:
public static void RetrieveFormatedAddress(string lat1, string lng1)
{
static string baseUri = "http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&language=fa&sensor=true";
string requestUri = string.Format(baseUri, lat1, lng1);
using (WebClient wc = new WebClient())
{
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri(requestUri));
}
}
static void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var xmlElm = XElement.Parse(e.Result);
var status = (from elm in xmlElm.Descendants()
where elm.Name == "status"
select elm).FirstOrDefault();
if (status.Value.ToLower() == "ok")
{
var res = (from elm in xmlElm.Descendants()
where elm.Name == "formatted_address"
select elm).FirstOrDefault();
Console.WriteLine(res.Value);
Console.WriteLine(res);
GetSMS getsms1 = new GetSMS();
getsms1.retrunAdress(res.Value);
}
else
{
Console.WriteLine("error");
}
}
And google returned me :
طھظ‡ط±ط§ظ†طŒ طھظ‡ط±ط§ظ†طŒ ط®غŒط§ط¨ط§ظ† ط§ظ…غŒط±غŒ ط·ط§ط¦ظ…ظ‡طŒ ط§غŒط±ط§ظ†
How can i get the 'Farsi' language address from google? Thank you
After 2 days of searching on net and test a lot different codes, Finally i found the solution. My codes are right but only need the set UTF-8 Unicode on web-client object. So my code will change to this:
using (WebClient wc = new WebClient())
{
wc.Encoding = Encoding.UTF8;
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri(requestUri));
}
this will work in UTF-8 as well.