Reputation:
Whenever i print out the out of the Geocoding to a csv file. it names it item1 and item 2. so i want to change it to to latitude and longitude. the code is use of the conversion is:
static List<Tuple<string, string>> GeoCoding(string address)
{
var json = new WebClient().DownloadString(baseUrlGC + address.Replace(" ", "+")
+ plusUrl);//concatenate URL with the input address and downloads the requested resource
var jsonResult = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(json);
if (jsonResult.status == "ZERO_RESULTS")
return new List<Tuple<string, string>> { new Tuple<string, string>("N/A", "N/A") };
if (jsonResult.status != "OK")
throw new Exception($"Request failed with {jsonResult.status}");
return jsonResult.results
.Select(result => result.geometry.location)
.Select(loc => new Tuple<string, string>(loc.lat, loc.lng))
.ToList();
}
Upvotes: 0
Views: 68
Reputation: 219077
i want to change it to to latitude and longitude
Use a type with those properties then. For example:
public class Coordinates
{
public string Latitude { get; set; }
public string Longitude { get; set; }
}
(Or a struct
, or a record
, whatever is best for your needs.)
Change your method to return that type:
static List<Coordinates> GeoCoding(string address)
And return objects of that type:
.Select(loc => new Coordinates { Latitude = loc.lat, Longitude = loc.lng })
You can't re-name the properties on built-in types, but you can define your own types all you like.
Upvotes: 2