I have my code working fine, but I can't seem to be able to get to the deeper parts of the tree. I'm trying to pull the longitude and the latitude. The code below pulls 'status' no problem as 'OK" (at the very end of the response). What is the syntax for 'geometry' -> 'location' -> 'lat' and 'lng'?
Here is my code:
string RawAddress = "163 Leektown Road, New Gretna, NJ 08004";
string Address = RawAddress.Replace(" ", "+");
string AddressURL = "http://maps.google.com/maps/api/geocode/json?address=" + Address;
var result = new System.Net.WebClient().DownloadString(AddressURL);
dynamic data = JObject.Parse(result);
Lat.Text = data.status;
This is what the API generates:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Mountain View, CA, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 37.4508789,
"lng" : -122.0446721
},
"southwest" : {
"lat" : 37.3567599,
"lng" : -122.1178619
}
},
"location" : {
"lat" : 37.3860517,
"lng" : -122.0838511
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.4508789,
"lng" : -122.0446721
},
"southwest" : {
"lat" : 37.3567599,
"lng" : -122.1178619
}
}
},
"partial_match" : true,
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}