1、 阿里的提供的restful api
2. springmvc下geoip2获取location实现(亲测可行。以下代码直接copy即可用)
maven的pom.xml里导入geoip2
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>2.2.0</version>
</dependency>
下载最新的GeoLite2-City.mmdb和GeoLiteCity.dat
可以到官网下载或者在我的csdn资源库下载:
我的csdn资源库:https://download.csdn.net/download/qq_23832313/10501973
使用实体类保存国家信息
public class GeoLocation {
private String countryCode;
private String countryName;
private String region;
private String regionName;
private String city;
private String postalCode;
private String latitude;
private String longitude;
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public String getRegion() {
return region;
<