Skip to content

Instantly share code, notes, and snippets.

@suchithm
Last active August 29, 2015 14:27
Show Gist options
  • Save suchithm/e7bb13e0ccf6c82e992a to your computer and use it in GitHub Desktop.
Save suchithm/e7bb13e0ccf6c82e992a to your computer and use it in GitHub Desktop.
void FnGeoCodeApi()
{
string strGeoCode = string.Format ("address={0}","Silicon Valley,CA,USA");
string strGeoCodeFullURL = string.Format (Constants.strGeoCodingUrl,strGeoCode);
string strResult=await FnHttpRequest(strGeoCodeFullURL);
if ( strResult != Constants.strException )
{
var objGeoCodeClass= JsonConvert.DeserializeObject<GoogleGeoCodeClass> (strResult);
if ( objGeoCodeClass.status == "OK" )
{
var Position = new LatLng ( objGeoCodeClass.results [0].geometry.location.lat , objGeoCodeClass.results [0].geometry.location.lng );
string address = objGeoCodeClass.results [0].formatted_address;
}
}
}
WebClient webclient;
async Task<string> FnHttpRequest(string strUri)
{
webclient = new WebClient ();
string strResultData;
try
{
strResultData= await webclient.DownloadStringTaskAsync (new Uri(strUri));
Console.WriteLine(strResultData);
}
catch
{
strResultData = Constants.strException;
}
finally
{
if ( webclient!=null )
{
webclient.Dispose ();
webclient = null;
}
}
return strResultData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment