如何为我的网站使用Geolocation API? [英] how to use Geolocation API for my website?
本文介绍了如何为我的网站使用Geolocation API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家
我希望知道正在访问我网站的人们的地理位置.要了解地理位置,一些朋友建议在下面的链接中进行.
http://npdoty.name/location/#developer [ http://dev.w3.org/geo/api/spec-source.html#position [ ^ ]
http://ipinfodb.com/index.php [
hi experts
i am wishing to know the people''s geographic location who are visiting my website. To know the geographic location some friends suggested below links.
http://npdoty.name/location/#developer[^]
http://dev.w3.org/geo/api/spec-source.html#position[^]
http://ipinfodb.com/index.php[^]
But i can''t understand how to consume those services to my site. If you know that could you please advise.
thanks in advance...
推荐答案
public static GeoPlugin FindMoreIpDetails(String IPAddress)
{
String httpCall = "http://www.geoplugin.net/asp.gp?ip=" + IPAddress;
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(httpCall);
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader loResponseStream = new StreamReader(WebResp.GetResponseStream(), enc);
GeoPlugin plugin = new GeoPlugin();
plugin.ReceivedResponse = loResponseStream.ReadToEnd();
String[] inParts = plugin.ReceivedResponse.Split('\"');
// now the ODD numbers in inParts[x] is the wanted data
if (inParts.Length.Equals(29)) // there should be 29 parts
{
Double result = 0;
Int32 regionCode = 0;
plugin.City = inParts[1];
plugin.Region = inParts[3]; // and so on till InParts[27]
plugin.AreaCode = inParts[5];
plugin.DmaCode = inParts[7];
plugin.CountryCode = inParts[9];
plugin.CountryName = inParts[11];
plugin.ContinentCode = inParts[13];
plugin.Lattitude = Double.TryParse(inParts[15], NumberStyles.Float, CultureInfo.GetCultureInfo("EN-us"), out result) ? result : 0;
plugin.Longitude = Double.TryParse(inParts[17], NumberStyles.Float, CultureInfo.GetCultureInfo("EN-us"), out result) ? result : 0;
plugin.RegionCode = Int32.TryParse(inParts[19], out regionCode) ? regionCode : 0;
plugin.RegionName = inParts[21];
plugin.CurrencyCode = inParts[23];
plugin.CurrencySymbol = inParts[25];
plugin.CurrencyConverter = Double.TryParse(inParts[27], NumberStyles.Float, CultureInfo.GetCultureInfo("EN-us"), out result) ? result : 0;
}
loResponseStream.Close();
WebResp.Close();
return plugin;
}
public class GeoPlugin
{
/*
* Known Response:
* geoplugin_city=@0"Apeldoorn"@1geoplugin_region=@2"Gelderland"@3geoplugin_areaCode=@4"0"@5geoplugin_dmaCode=@6"0"
* @7geoplugin_countryCode=@8"NL"@9geoplugin_countryName=@10"Netherlands"@11geoplugin_continentCode=@12"EU"
* @13geoplugin_latitude=@14"52.216701507568"@15geoplugin_longitude=@16"5.9667000770569"
* @17geoplugin_regionCode=@18"03"@19geoplugin_regionName=@20"Gelderland"@21geoplugin_currencyCode=@22"EUR"
* @23geoplugin_currencySymbol=@24"€"@25geoplugin_currencyConverter=@26"0.6913855239"@27
*/
public String City;
public String Region;
public String AreaCode;
public String DmaCode;
public String CountryCode;
public String CountryName;
public String ContinentCode;
public Double Lattitude;
public Double Longitude;
public int RegionCode;
public String RegionName;
public String CurrencyCode;
public String CurrencySymbol;
public Double CurrencyConverter;
public String ReceivedResponse;
}
这篇关于如何为我的网站使用Geolocation API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文