[英]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.