Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

MVC, Google Place Type, import

I start with the following codes with mvc/json/c#
and I just want to know how to get the following items
Or there is easier way to get everything inside of json file. that will be great.


rating
open now
weekday text
viewport
photos height
photos html_attributions


https://developers.google.com/places/web-service/search

WebClient wc = new WebClient();
string jsonStr = wc.DownloadString("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.753,-122.443&radius=10000&type=rv_park&key=AIzaSyCietasdfasdfasdfasdfxzD65Uc19X6DgrJFumdi-nCZYSHjg");
GooglePlacesResponse gpr = (GooglePlacesResponse)JsonConvert.DeserializeObject<GooglePlacesResponse>(jsonStr);
Response.Write(gpr.status + "<br><br>");

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

I think this is the best and nicest way IMO...

public class GooglePlacesResponse
{
    public string status { get; set; }
    public results[] results { get; set; }
}

public class results
{
    public geometry geometry { get; set; }
    public string name { get; set; }
    public string reference { get; set; }
    public string vicinity { get; set; }
    public float rating { get; set; }
    public bool open_now { get; set; }
    public photo[] photos { get; set; }
}

public class geometry
{
    public location location { get; set; }
}

public class photo
{
    public int height { get; set; }
    public string[] html_attributions { get; set; }
    public string photo_reference { get; set; }
    public int width { get; set; }
}

public class location
{
    public string lat { get; set; }
    public string lng { get; set; }
}

Open in new window

Avatar of ITsolutionWizard

ASKER

so what I need to do with the classes you posted?
use it the same way you did it for the status : gpr.status
so, for exampel :
if(gpr.results.length>0)
{
    if(gpr.results[0].photos.length>0)
    {
           Response.Write(gpr.results[0].photos[0].photo_reference + "<br><br>");

Open in new window

it just returns one record from your codes., do you know how to get all of them?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
leakim971 got me best solution