com.maxmind.geoip2.record.City Java Examples

The following examples show how to use com.maxmind.geoip2.record.City. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocRecord.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
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();
	final Map<String, String> names = new HashMap<>();
	names.put("name", "Loc record");
	final City city = new City(null, null, null, names);
	final Country country = new Country(null, 0, 0, LOC, names);
	final Location loc = new Location(0, 0, lat, lon, null, null, null);
	location = new CityResponse(city, null, country, loc, null, null, null, null, null, null);
	valid = true;
}
 
Example #2
Source File: MaxMindGeoLocationServiceTest.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
@Test
public void lookupShouldReturnCountryIsoWhenDatabaseReaderWasSet() throws NoSuchFieldException, IOException,
        GeoIp2Exception {
    // given
    final Country country = new Country(null, null, null, "fr", null);
    final Continent continent = new Continent(null, "eu", null, null);
    final City city = new City(singletonList("test"), null, null, singletonMap("test", "Paris"));
    final Location location = new Location(null, null, 48.8566, 2.3522,
            null, null, null);
    final ArrayList<Subdivision> subdivisions = new ArrayList<>();
    subdivisions.add(new Subdivision(null, null, null, "paris", null));
    final CityResponse cityResponse = new CityResponse(city, continent, country, location, null,
            null, null, null, subdivisions, null);

    final DatabaseReader databaseReader = Mockito.mock(DatabaseReader.class);
    given(databaseReader.city(any())).willReturn(cityResponse);

    FieldSetter.setField(maxMindGeoLocationService,
            maxMindGeoLocationService.getClass().getDeclaredField("databaseReader"), databaseReader);

    // when
    final Future<GeoInfo> future = maxMindGeoLocationService.lookup(TEST_IP, null);

    // then
    assertThat(future.succeeded()).isTrue();
    assertThat(future.result())
            .isEqualTo(GeoInfo.builder()
                    .vendor("maxmind")
                    .continent("eu")
                    .country("fr")
                    .region("paris")
                    .city("Paris")
                    .lat(48.8566f)
                    .lon(2.3522f)
                    .build());
}
 
Example #3
Source File: GEOInfo.java    From proxylive with MIT License 4 votes vote down vote up
public City getCity() {
    return city;
}
 
Example #4
Source File: GEOInfo.java    From proxylive with MIT License 4 votes vote down vote up
public void setCity(City city) {
    this.city = city;
}