C# “请求”;“外国”;ASP.NET Web Api中的Api
我写了一个WebAPI2项目,在一个方法中(发布一个新位置),我想检索一些用户没有提供的信息(国家、城市、地区) 我在谷歌地图API中找到了一个解决方案:C# “请求”;“外国”;ASP.NET Web Api中的Api,c#,asp.net-web-api,C#,Asp.net Web Api,我写了一个WebAPI2项目,在一个方法中(发布一个新位置),我想检索一些用户没有提供的信息(国家、城市、地区) 我在谷歌地图API中找到了一个解决方案: http://maps.googleapis.com/maps/api/geocode/json?latlng=38.91845,1.44315和传感器=真 本次会议,我必须只提供此URL内的lat和lon坐标。 如何发送此请求并在自己的API方法中处理结果 到目前为止,我的方法是: public string PostNewLocation
http://maps.googleapis.com/maps/api/geocode/json?latlng=38.91845,1.44315和传感器=真
本次会议,我必须只提供此URL内的lat和lon坐标。
如何发送此请求并在自己的API方法中处理结果
到目前为止,我的方法是:
public string PostNewLocation(string mName, decimal mLat, decimal mLot)
{
// Here should be the calling and resolving of the Google API
// string mCity = ...
// string mCountry = ...
// Adding new location to database follows here and works fine...
}
看起来不错,但是在哪里可以找到以及如何实现GoogleAppService
?这是您自己要实现的任务。把它分解成小步骤。因此1)从url获取Json响应。2) 反序列化到您自己的对象中。这是我引入的问题:如何发送请求并从URL获取响应…使用System.Net.Http.HttpClient。对不起,我没有时间完整回答。
public string PostNewLocation(string mName, decimal mLat, decimal mLot)
{
//do a get request to http://maps.googleapis.com/maps/api/geocode/json?latlng=38.91845,1.44315&sensor=true
//deserialize the json response to your own object and do stuff with it
var response = googleAPIService.Get(mLat, mLot);
//do something with the response
}