我目前正在使用地理定位来获取用户的国家/地区名称。这是我的代码:
navigator.geolocation.getCurrentPosition(function (pos) {
var latlng = pos.coords.latitude + "," + pos.coords.longitude;
var apiurl = 'http://maps.google.com/maps/geo?output=json&sensor=false&q=' + latlng;
var yqlqry = encodeURIComponent('select * from json where url="' + apiurl + '"');
var yqlurl = 'http://query.yahooapis.com/v1/public/yql?q=' + yqlqry + '&format=json&callback=?';
$.getJSON(yqlurl, function (data) {
var countryName = data.query.results.json.Placemark.AddressDetails.Country.CountryName;
var newCountryName = countryName.toLowerCase();
if (newCountryName == "united states")
newCountryName = "us";
else if (newCountryName == "england" || newCountryName == "ireland" || newCountryName == "scotland" || newCountryName == "wales" || newCountryName == "northern ireland")
newCountryName = "uk";
else if (newCountryName == "australia")
newCountryName = "au";
else if (newCountryName == "canada")
newCountryName = "ca";
else
newCountryName = "world";
$('a[title = "' + newCountryName + '"]').trigger('click');
});
});
我宁愿在服务器端使用一些东西。有谁知道您是否可以在 C# 中获取用户的国家/地区名称?
最佳答案
在服务器端,您唯一可以回复的是 IP 地址,您可以使用它来执行位置查找。有免费的 IP 地址到位置映射的数据库,或者您可以使用 HostIP.info。
关于c# - 你如何在 C# 中获取用户的国家/地区名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8897773/