Regarding google places API

后端 未结 1 1383
南旧
南旧 2021-01-03 15:36

What I want to know is that using Google places API. Basically I want to create a site like www.zomato.com

1) Can I show listing of all restaurants and their individ

1条回答
  •  时光说笑
    2021-01-03 15:44

    If we look at the documentation for the Google Places API, we can see the format of the JSON that a request to the API returns. By using json2csharp, we can then easily generate a C# model for the response to a Google Places query.

    public class Location
    {
        public double lat { get; set; }
        public double lng { get; set; }
    }
    
    public class Geometry
    {
        public Location location { get; set; }
    }
    
    public class OpeningHours
    {
        public bool open_now { get; set; }
        public List weekday_text { get; set; }
    }
    
    public class Photo
    {
        public int height { get; set; }
        public List html_attributions { get; set; }
        public string photo_reference { get; set; }
        public int width { get; set; }
    }
    
    public class Result
    {
        public Geometry geometry { get; set; }
        public string icon { get; set; }
        public string id { get; set; }
        public string name { get; set; }
        public OpeningHours opening_hours { get; set; }
        public List photos { get; set; }
        public string place_id { get; set; }
        public double rating { get; set; }
        public string reference { get; set; }
        public string scope { get; set; }
        public List types { get; set; }
        public string vicinity { get; set; }
    }
    
    public class PlacesApiQueryResponse
    {
        public List html_attributions { get; set; }
        public List results { get; set; }
        public string status { get; set; }
    }
    
    
    

    With a simple HTTP request to the Google Places API, we can then deserialize the query results using Json.NET.

    using (var client = new HttpClient())
    {
        var response = await client.GetStringAsync(string.Format("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={0},{1}&radius=500&type=bar&key=YourAPIKey", latitude, longitude));
        var result = JsonConvert.DeserializeObject(response);
    }
    

    0 讨论(0)
    提交回复
    热议问题