通过Google API ** 获得客户端ip地址的地理位置**,

首先要引用google提供的JavaScript接口文件

下面是次接口的用法:

eg.

无标题页

var area = “”;
var country=””;
var pro=””;
var city=””;
try
{
if(geoip_city() != “” && geoip_city() != null)
area += geoip_city()+” “;
city=geoip_city(); //城市名称
if(geoip_region_name() != “” && geoip_region_name() != null)
area += geoip_region_name()+” “;
pro=geoip_region_name();//地区名称
if(geoip_country_name() != “” && geoip_country_name() != null)
area += geoip_country_name();
country=geoip_country_name();//国家名称
}
catch(err)
{
area=””;
}
if(area!=””)
{
if(pro!=city)//判断是否是直辖市,如上海
{
document.write(“Welocome you, come from the friend of “+ area);
}
else
{
document.write(“Welocome you, come from the friend of “+ city +” “+ country);
}
}

其中:还有另外3个方法可以调用,分别是:geoip_country_code():表示国家代码
geoip_latitude():表示经度 ? ? ? geoip_longitude()表示纬度

本文原创,转载请注明来源:http://happysnail.org/index.php/archives/371