fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. // your code goes here
  8. }
  9. public static async Task<DbGeography> GetLatLongForAddress(string location)
  10. {
  11. float[] latLong = new float[2];
  12. var add = string.Format("http://m...content-available-to-author-only...s.com/maps/api/geocode/xml?address={0}&sensor=false", location.Replace("#", "%23"));
  13. string result;
  14.  
  15. using (var hc = new HttpClient())
  16. {
  17. return await (await hc.GetStringAsync(add).ContinueWith(async task =>
  18. {
  19. if (task.IsFaulted)
  20. {
  21. var ex = task.Exception;
  22. }
  23. result = task.Result;
  24. var doc = XDocument.Parse(result);
  25. string status = doc.Element("GeocodeResponse").Element("status").Value;
  26. //no errors occurred; the address was successfully parsed and at least one geocode was returned.
  27.  
  28. if (status.Equals("OK"))
  29. {
  30. var point = doc.Element("GeocodeResponse").Element("result").
  31. Element("geometry").Element("location");
  32.  
  33. string lat = point.Element("lat").Value;
  34. string lng = point.Element("lng").Value;
  35. latLong[0] = (float)Convert.ToDouble(lat);
  36. latLong[1] = (float)Convert.ToDouble(lng);
  37.  
  38. }
  39. else if (status.Equals("ZERO_RESULTS"))
  40. {
  41. //geocode was successful but returned no results
  42. throw new ApplicationException("No maps found for this address");
  43.  
  44. }
  45. else if (status.Equals("REQUEST_DENIED"))
  46. {
  47. //request was denied
  48. throw new ApplicationException("Request Denied");
  49.  
  50. }
  51. else if (status.Equals("INVALID_REQUEST"))
  52. {
  53. //address is missing
  54. throw new ApplicationException("Address not found");
  55. }
  56. else if (status.Equals("UNKNOWN_ERROR"))
  57. {
  58. //the request could not be processed due to a server error
  59. //throw new ApplicationException("Unknown Error. Try agian.");
  60. return await GetLatLongForAddress(location);
  61. }
  62. var ret = DbGeography.FromText(string.Format("POINT({1} {0})", latLong[0], latLong[1]));
  63. return ret;
  64. }));
  65. }
  66.  
  67. }
  68. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(9,66): error CS1519: Unexpected symbol `GetLatLongForAddress' in class, struct, or interface member declaration
prog.cs(9,47): error CS1520: Class, struct, or interface method must have a return type
prog.cs(17,36): error CS1525: Unexpected symbol `hc'
prog.cs(17,78): error CS1525: Unexpected symbol `task'
prog.cs(60,41): error CS1525: Unexpected symbol `GetLatLongForAddress'
prog.cs(17,79): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
prog.cs(64,21): error CS1525: Unexpected symbol `)', expecting `;'
Compilation failed: 7 error(s), 0 warnings
stdout
Standard output is empty