The first post you post here is as complete newb, so apologize if I don't post this question correctly.
I have a structure for storing 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'm trying to call the Post Create method method to populate the coordinate values ββwith the location coordinates provided by the Google Maps API, which provides a back-formatted JSON data stream.
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" that the result contains JSON, which has (among many other attributes) the location coordinates in it that I want to return, I just have problems with the syntax to "parse" the location attributes and return them to my method create.
In the JSON renderer, the coordinates are in JSON [0] .geometry.location.lat and JSON [0] .geometry.location.lng, and I assume (?!) That JSON [0] .geometry. location contains an object that must be compatible (ish) with my structure. I am happy to make changes to the structure to make it compatible if necessary!
Thanks in advance for any help / understanding you can give!
source share