关于谷歌地点 API [英] Regarding google places API

查看:33
本文介绍了关于谷歌地点 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

1) Can I show listing of all restaurants and their individual details with all the details in my city just like Google+ business page?

2) 是否可以在 C#.net 中使用此 API?

2) Is is possible to use this API with C#.net?

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

3) How much Google will charge for this?

推荐答案

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

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<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.

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<PlacesApiQueryResponse>(response);
}

这篇关于关于谷歌地点 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆