Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# “请求”;“外国”;ASP.NET Web Api中的Api_C#_Asp.net Web Api - Fatal编程技术网

C# “请求”;“外国”;ASP.NET Web Api中的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

我写了一个WebAPI2项目,在一个方法中(发布一个新位置),我想检索一些用户没有提供的信息(国家、城市、地区)

我在谷歌地图API中找到了一个解决方案:

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

}