First time posting here as a total newb so apologies if I'm not going about posting this question in the right way
I have a struct to hold Geo coordinates in a .NET MVC5 project
public struct GeoCoordinate
{
private readonly double latitude;
private readonly double longitude;
public double Latitude { get { return latitude; } }
public double Longitude { get { return longitude; } }
public GeoCoordinate(double latitude, double longitude)
{
this.latitude = latitude;
this.longitude = longitude;
}
public override string ToString()
{
return string.Format("{0},{1}", Latitude, Longitude);
}
}
I am attempting to call a method on the Post Create method to fill the coordinate values with location coordinates provided by the Google Maps API- which provides a JSON formatted datastream back.
public GeoCoordinate GEOCodeAddress(String Address)
{
var address = String.Format("https://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false", Address.Replace(" ", "+"));
var result = new System.Net.WebClient().DownloadString(address);
JavaScriptSerializer jss = new JavaScriptSerializer();
return jss.Deserialize<dynamic>(result);
}
I can "see" the result contains JSON which has in it (among lots of other attributes) the location coordinates that I'm looking to return, I'm just having issues with the syntax to "parse" out these location attributes and return them to my create method.
In the JSON visualiser the coordinates are in JSON[0].geometry.location.lat and JSON[0].geometry.location.lng and I'm guessing (?!) that the JSON[0].geometry.location contains an object that should be compatible (ish) with my struct. Am happy to amend the struct to make it compatible if necessary!
Thanks in advance for any help/insight you can give!