本文整理汇总了Java中com.maxmind.geoip.Location类的典型用法代码示例。如果您正苦于以下问题:Java Location类的具体用法?Java Location怎么用?Java Location使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Location类属于com.maxmind.geoip包,在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LocRecord
import com.maxmind.geoip.Location; //导入依赖的package包/类
public LocRecord(final String owner, final double lat, final double lon) {
this.owner = owner;
final StringBuilder sb = new StringBuilder();
//owner TTL class LOC ( d1 [m1 [s1]] {"N"|"S"} d2 [m2 [s2]] {"E"|"W"} alt["m"] [siz["m"] [hp["m"] [vp["m"]]]] )
final double[] latDms = Angle.fromDegreesLatitude(lat).toDMS();
final double[] lonDms = Angle.fromDegreesLatitude(lon).toDMS();
sb.append(owner).append(".").append(SPACE).append(0).append(SPACE).append("IN").append(SPACE).append("LOC").append(SPACE);
sb.append(Math.abs((int) latDms[0])).append(SPACE).append((int) latDms[1]).append(SPACE).append((float) latDms[2]).append(SPACE).append(lat >= 0 ? "N" : "S")
.append(SPACE);
sb.append(Math.abs((int) lonDms[0])).append(SPACE).append((int) lonDms[1]).append(SPACE).append((float) lonDms[2]).append(SPACE).append(lon >= 0 ? "E" : "W")
.append(SPACE);
sb.append("0m").append(SPACE).append("0m").append(SPACE).append("0m").append(SPACE).append("0m");
raw = sb.toString();
location = new Location();
location.countryCode = LOC;
location.countryName = "Loc record";
location.latitude = (float) lat;
location.longitude = (float) lon;
valid = true;
}
示例2: getCountryCode
import com.maxmind.geoip.Location; //导入依赖的package包/类
/**
* <p>Query if there is a country code for a given IP.</p>
* @param ip This is the address to query the data base.
* @return The country code, example: US, ES, FR.
*/
private String getCountryCode(String ip) {
Matcher match = VALID_IPV4_PATTERN.matcher(ip);
String countryCode = null;
Location location;
if (match.matches()) {
location = _city.getLocation(ip);
} else {
location = _city6.getLocationV6(ip);
}
if (location != null) {
countryCode = location.countryCode;
}
return countryCode;
}
示例3: extractInformation
import com.maxmind.geoip.Location; //导入依赖的package包/类
@Override
public Map<String, Object> extractInformation(Object value)
{
Map<String, Object> m = new HashMap<String, Object>();
try {
Location location = reader.getLocation(value.toString());
if (location != null) {
m.put("ipCountry", location.countryCode);
m.put("ipRegion", location.region);
m.put("ipCity", location.city);
}
} catch (Exception ex) {
LOG.error("Caught exception when looking up Geo IP for {}:", value, ex);
}
return m;
}
示例4: getLocation
import com.maxmind.geoip.Location; //导入依赖的package包/类
public UserLocation getLocation(String ipAddress, File file) {
UserLocation serverLocation = null;
try {
serverLocation = new UserLocation();
LookupService lookup = new LookupService(file,LookupService.GEOIP_MEMORY_CACHE);
Location locationServices = lookup.getLocation(ipAddress);
serverLocation.setCountryCode(locationServices.countryCode);
serverLocation.setCountryName(locationServices.countryName);
serverLocation.setRegion(locationServices.region);
serverLocation.setRegionName(regionName.regionNameByCode(locationServices.countryCode, locationServices.region));
serverLocation.setCity(locationServices.city);
serverLocation.setPostalCode(locationServices.postalCode);
serverLocation.setLatitude(String.valueOf(locationServices.latitude));
serverLocation.setLongitude(String.valueOf(locationServices.longitude));
} catch (IOException e) {
System.err.println(e.getMessage());
}
return serverLocation;
}
示例5: updateModel
import com.maxmind.geoip.Location; //导入依赖的package包/类
public void updateModel() {
synchronized (peerInfoList) {
peerInfoList.clear();
final Set<org.ethereum.net.peerdiscovery.PeerInfo> peers = UIEthereumManager.ethereum.getPeers();
synchronized (peers){
for (org.ethereum.net.peerdiscovery.PeerInfo peer : peers) {
InetAddress addr = peer.getAddress();
Location cr = IpGeoDB.getLocationForIp(addr);
peerInfoList.add(new PeerInfo(cr, addr, peer.isOnline(), peer.getLastCheckTime(),
peer.getHandshakeHelloMessage(), peer.getStatusMessage()));
}
}
}
}
示例6: getGeolocation
import com.maxmind.geoip.Location; //导入依赖的package包/类
public Geolocation getGeolocation(long ipAddress) {
Geolocation result = null;
Location location = null;
try {
location = geoIpLookup.getLocation(ipAddress);
} catch (RuntimeException e) {
log.error("Cannot lookup geolocation from ip-adress: " + ipAddress, e);
}
if (location != null) {
if (log.isDebugEnabled()) {
log.debug("Geolocation for ip-address " + ipAddress + ": " + location.latitude + "/" + location.longitude + " (" + location.countryCode + ")");
}
result = new Geolocation(location);
}
return result;
}
示例7: GetLocationServices
import com.maxmind.geoip.Location; //导入依赖的package包/类
public FeedEntry GetLocationServices() {
FeedEntry entry = null;
try {
if (this.database == null) {
return entry;
}
LookupService lookup = new LookupService(this.database, LookupService.GEOIP_MEMORY_CACHE);
Location locationServices = lookup.getLocation(LocationInfo.getIp());
if (locationServices == null) {
return entry;
}
String City = locationServices.city;
String CountryCode = locationServices.countryCode;
entry = new FeedEntry();
entry.setLocation(City);
entry.setCountryCode(CountryCode);
entry.setDays(7);
} catch (Exception ex) {
ex.printStackTrace();
return entry;
}
return entry;
}
示例8: addLocRecord
import com.maxmind.geoip.Location; //导入依赖的package包/类
private void addLocRecord(final LocRecord record) {
if (record.isValid()) {
final Location old = _locRecords.put(record.getOwner(), record.getLocation());
if (old != null) {
_rawLocRecords.remove(old);
}
}
_rawLocRecords.add(record);
}
示例9: ipToCountry
import com.maxmind.geoip.Location; //导入依赖的package包/类
/**
* This method takes ip address an input and convert it into country name.
*
* @param ip
* @return
*/
public String ipToCountry(String ip) {
Location location = cl.getLocation(ip);
if (location == null) {
return "NA";
}
if (location.countryName == null) {
return "NA";
}
return location.countryName;
}
示例10: getLocation
import com.maxmind.geoip.Location; //导入依赖的package包/类
public ServerLocation getLocation(String ipAddress, File file) {
ServerLocation serverLocation = null;
try {
serverLocation = new ServerLocation();
LookupService lookup = new LookupService(file, LookupService.GEOIP_MEMORY_CACHE);
Location locationServices = lookup.getLocation(ipAddress);
serverLocation.setCountryCode(locationServices.countryCode);
serverLocation.setCountryName(locationServices.countryName);
serverLocation.setRegion(locationServices.region);
serverLocation.setRegionName(regionName.regionNameByCode(
locationServices.countryCode, locationServices.region));
serverLocation.setCity(locationServices.city);
serverLocation.setPostalCode(locationServices.postalCode);
serverLocation.setLatitude(String.valueOf(locationServices.latitude));
serverLocation.setLongitude(String.valueOf(locationServices.longitude));
} catch (IOException e) {
System.err.println(e.getMessage());
}
return serverLocation;
}
示例11: getLocationForIp
import com.maxmind.geoip.Location; //导入依赖的package包/类
public static Location getLocationForIp(InetAddress ip) {
try {
return cl.getLocation(ip);
} catch (Throwable e) {
// TODO: think about this exception, maybe you can do something more reasonable
logger.error(e.getMessage(), e);
}
return null;
}
示例12: PeerInfo
import com.maxmind.geoip.Location; //导入依赖的package包/类
private PeerInfo(Location location, InetAddress ip,
boolean isConnected, long lastAccessed, HelloMessage helloMessage, StatusMessage statusMessage) {
if (location == null)
this.location = new Location();
else
this.location = location;
this.ip = ip;
this.connected = isConnected;
this.lastAccessed = lastAccessed;
this.handshakeHelloMessage = helloMessage;
this.handshakeStatusMessage = statusMessage;
}
示例13: findByIpAddress
import com.maxmind.geoip.Location; //导入依赖的package包/类
/**
* Lookup the location (country, region, city) from an IP address.
*
* @param ipAddress
* @return Location
*/
public Location findByIpAddress(String ipAddress) {
if (lookupService == null)
return null;
else {
Location location = lookupService.getLocation(ipAddress);
return location;
}
}
示例14: populateGeoDataForIP
import com.maxmind.geoip.Location; //导入依赖的package包/类
public <P extends GeoPoint> P populateGeoDataForIP(final P point, final String ip, final String dns, final P pointIfUnknown) {
Location location = null;
try {
point.setIp(ip);
// check loc records
if (DNSLookupService.UNKNOWN_HOST.equals(dns)) {
location = _locRecords.get(ip);
} else {
if (dns == null) {
location = _locRecords.get("localhost");
} else {
location = _locRecords.get(dns);
}
}
// nothing in the loc records, check with the geoip db
if (location == null) {
location = _lookupService.getLocation(ip);
}
if (location != null) {
final String city = location.city;
final String country = location.countryName;
float lat = location.latitude;
float lon = location.longitude;
if (city == null || "".equals(city)) {
point.setTown(UNKNOWN_LOCATION);
if (pointIfUnknown != null && pointIfUnknown.getCountry().equals(country)) {
lat = pointIfUnknown.getLat();
lon = pointIfUnknown.getLon();
}
} else {
point.setTown(city);
}
if (country == null || "".equals(country)) {
point.setCountry(UNKNOWN_LOCATION);
} else {
point.setCountry(country);
}
if (lat == 0f && lon == 0f) {
point.setUnknownGeo(true);
} else {
point.setLat(lat);
point.setLon(lon);
}
point.setCountryIso(location.countryCode);
if (ip.equals("239.255.255.250")) {
point.setCountry("SSDP");
point.setTown("SSDP");
}
}
} catch (final Exception e) {
LOGGER.warn("Failed to lookup geoip data for ip " + ip, e);
}
if (location == null) {
point.setUnknownGeo(true);
point.setTown(UNKNOWN_LOCATION);
point.setCountry(UNKNOWN_LOCATION);
}
return point;
}
示例15: getLocation
import com.maxmind.geoip.Location; //导入依赖的package包/类
private Location getLocation() {
return location;
}