繁体   English   中英

关于Google Places API

[英]Regarding google places API

我想知道的是使用Google Places API。 基本上我想创建一个像www.zomato.com这样的网站

1)是否可以像我的Google+商户页面一样显示城市中所有餐厅的列表及其个人详细信息?

2)是否可以将此API与C#.net一起使用?

3)Google将为此收取多少费用?

如果我们查看Google Places API文档 ,则可以看到对API的请求返回的JSON格式。 通过使用json2csharp ,我们可以轻松生成用于响应Google Places查询的C#模型。

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<object> weekday_text { get; set; }
}

public class Photo
{
    public int height { get; set; }
    public List<string> 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<Photo> 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<string> types { get; set; }
    public string vicinity { get; set; }
}

public class PlacesApiQueryResponse
{
    public List<object> html_attributions { get; set; }
    public List<Result> results { get; set; }
    public string status { get; set; }
}

通过对Google Places API的简单HTTP请求,我们可以使用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<PlacesApiQueryResponse>(response);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM