Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to fetch all the latitude and longitude of my JSON result.
JSON Result (have many records):
HTML
"results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : 28.637255,
               "lng" : 77.05202800000001
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "aef56d078ec3fcab6f4a966bd944d3d59973bd72",
         "name" : "Homeopati Kendra",
         "opening_hours" : {
            "open_now" : false,
            "weekday_text" : []
         },
         "place_id" : "ChIJQavdFRwFDTkRMRAhjCbIOnI",
         "reference" : "CnRjAAAAwCoBEGDvsL4KeQNPyT2OsVF82b7FChIpUHRFQvGg8b1eR7FCv9I1nUPn0lFf50OVG9ug1PevkcZG813Lq9AAe1dK5GCgn99ajpQ1it9lafCwX3SaUwtiinLiepgptdHNz3NgDzhpVIx70a2D1KZcchIQvD4OS73_Jmr2wYQg4jtRjxoUjCnGT2M4XzDIXadJOtgA-LgRNR4",
         "scope" : "GOOGLE",
         "types" : [ "hospital", "health", "establishment" ],
         "vicinity" : "C-29 , Vikas Nagar,Uttam Nagar, Vikas Nagar Extn, Hastsal, New Delhi"
      },

for particular record (say record first):
C#
JObject obj = JObject.Parse(googleResult);
JArray jarr = (JArray)obj["results"];
double lt = (double)jarr[0]["geometry"]["location"]["lat"];
double lg = (double)jarr[0]["geometry"]["location"]["lng"];

for fetching all records:
C#
foreach(var item in jarr)
{
    double lt = Convert.ToDouble(item[jarr["geometry"]["location"]["lat"]]);
}

For fetching one record it works fine but for all records its not working.
Posted
Comments
F-ES Sitecore 1-Jul-15 20:07pm    
Try

foreach(var item in jarr)
{
double lt = Convert.ToDouble(item["geometry"]["location"]["lat"]);
// or maybe
//double lt = (double)item["geometry"]["location"]["lat"];
}

1 solution

C#
double lt = (double)item.SelectToken("geometry.location.lat");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900