在 mvc 5 中使用 google API 查找位置
Finding location using google API in mvc 5
我想根据我的项目的当前 URL 请求查找位置。
例如。如果用户登录,系统应该输出local area -> City -> country
来自 google API 并显示位置和 google 地图。
我使用过 freegeoip 并从中获取地理位置,如下所示。
URL:- http://freegeoip.net/xml/{ip}
在这里你可以提供你的IP并且可以在浏览器中看到结果。
在代码中实现。
string apiUrl = http://freegeoip.net/xml/{ip}
HttpClient HttpClient = new HttpClient();
var response = HttpClient.GetAsync(apiUrl).Result;
if (response != null && response.ReasonPhrase != "Unauthorized")
{
var myobject = response.Content.ReadAsStringAsync();
}
我想根据我的项目的当前 URL 请求查找位置。 例如。如果用户登录,系统应该输出local area -> City -> country 来自 google API 并显示位置和 google 地图。
我使用过 freegeoip 并从中获取地理位置,如下所示。
URL:- http://freegeoip.net/xml/{ip}
在这里你可以提供你的IP并且可以在浏览器中看到结果。
在代码中实现。
string apiUrl = http://freegeoip.net/xml/{ip}
HttpClient HttpClient = new HttpClient();
var response = HttpClient.GetAsync(apiUrl).Result;
if (response != null && response.ReasonPhrase != "Unauthorized")
{
var myobject = response.Content.ReadAsStringAsync();
}