java web 通过ip获取当前地理位置

0 篇文章 0 订阅
	public static void main(String[] args) throws Exception{	
		// A File object pointing to your GeoIP2 or GeoLite2 database	
		File database = new File("F:/定位/GeoLite2-City.mmdb");	
		// This creates the DatabaseReader object, which should be reused across	
		// lookups.	  
		DatabaseReader reader = new DatabaseReader.Builder(database).build();	  
		InetAddress ipAddress = InetAddress.getByName("14.106.124.11");	  
		// Replace "city" with the appropriate method for your database, e.g.,	 
		// "country".	  
		CityResponse response = reader.city(ipAddress);	  
		/*Country country = response.getCountry();	  
		System.out.println(country.getIsoCode());            // 'US'	 
		System.out.println(country.getName()); // 'United States'	
		System.out.println(country.getNames().get("zh-CN")); // '美国'	
		Subdivision subdivision = response.getMostSpecificSubdivision();
		System.out.println(subdivision.getName());   // 'Minnesota'	 
		System.out.println(subdivision.getIsoCode()); // 'MN'	  
*/		
		City city = response.getCity();
		System.out.println(city.getName()); // 'Minneapolis'
		Postal postal = response.getPostal();	
		System.out.println(postal.getCode()); // '55455'	 
		Location location = response.getLocation();	 
		System.out.println(location.getLatitude());  // 44.9733	 
		System.out.println(location.getLongitude()); // -93.2323 
		
	}
<a target=_blank href=">http://download.csdn.net/detail/ying890/9083051">下载Geolite2-city.mmdb</a><pre name="code" class="java">GeoLite2-City.mmdb
GeoLite2-City.mmdb
GeoLite2-City.mmdb

 
 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值