【发布时间】:2018-12-04 09:59:56
【问题描述】:
在我的 C# 项目中,我试图获取建筑物的经纬度位置。我将此线程用作Distance between addresses 的基础,并尝试对其进行调整以获取位置的经纬度。目前,从 API 获取 JSON 响应很好,它正在从 JSON 响应中获取我想要的值。
这是我目前的代码
string requesturl = url;
string content = fileGetContents(requesturl);
JObject o = JObject.Parse(content);
user.Latitude = (double)o.SelectToken("results[0].geometry[0].location[0].lat");
user.Longitude = (double)o.SelectToken("results[0].geometry[0].location[0].lng");
protected string fileGetContents(string fileName)
{
string sContents = string.Empty;
string me = string.Empty;
try
{
if (fileName.ToLower().IndexOf("https:") > -1)
{
System.Net.WebClient wc = new System.Net.WebClient();
byte[] response = wc.DownloadData(fileName);
sContents = System.Text.Encoding.ASCII.GetString(response);
}
else
{
System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
sContents = sr.ReadToEnd();
sr.Close();
}
}
catch { sContents = "unable to connect to server "; }
return sContents;
}
【问题讨论】:
-
请更新您的问题以包含
content的值。
标签: c# json google-maps google-geocoding-api