Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
GeoDB Java Client
https://github.com/wirefreethought/geodb-java-client
Admin
This library provides Java client bindings to the GeoDB Cities service.
Tokens:
1,086
Snippets:
14
Trust Score:
4.3
License:
MIT
Update:
3 months ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Find Cities by Name Prefix and Minimum Population Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Finds all cities in the US starting with 'San' and having a minimum population of 100,000. ```java PopulatedPlacesResponse placesResponse = geoDbApi.findPlaces( FindPlacesRequest.builder() .countryIds("US") .namePrefix("San") .minPopulation(100000) .types(Collections.singleton(PlaceRequestType.CITY)) .build() ); ``` -------------------------------- ### Initialize GeoDB API Service Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Create a GeoDbApi instance using the initialized apiClient to start making service calls. ```java GeoDbApi geoDbApi = new GeoDbApi(apiClient); // Execute service calls. (See below for examples.) geoDbApi.findCities(FindCitiesRequest.builder()...build()); ``` -------------------------------- ### Instantiate GeoDB API Client for PRO Service Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Instantiate the GeoDbApiClient for the PRO service. Remember to set your RapidAPI key. ```java GeoDbApiClient apiClient = new GeoDbApiClient(GeoDbInstanceType.PRO); apiClient.setApiKey(YOUR_RAPIDAPI_KEY); ``` -------------------------------- ### Instantiate GeoDB API Client for FREE Service Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Use this code to create an instance of the GeoDbApiClient when using the FREE GeoDB service. ```java GeoDbApiClient apiClient = new GeoDbApiClient(GeoDbInstanceType.FREE); ``` -------------------------------- ### Find Places by Region, Population, and Sorting Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Finds all cities in California with a minimum population of 100,000, sorted by population (low to high). ```java PopulatedPlacesResponse placesResponse = geoDbApi.findRegionPlaces( FindRegionPlacesRequest.builder() .countryId("US") .regionCode("CA") .minPopulation(100000) .types(Collections.singleton(PlaceRequestType.CITY)) .sort( GeoDbSort.builder() .fields(new SortField[] { new SortField(PlaceSortFields.FindPlaces.POPULATION, false) }) .build()) .build() ); ``` -------------------------------- ### Find Cities Near a Location with Population and Sorting Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Finds cities and towns within 50 miles of Los Angeles, with a minimum population of 50,000, sorted by population (high to low). ```java // Get the location for Los Angeles. PopulatedPlaceResponse placeResponse = geoDbApi.findPlaceById("Q65"); GeoLocation placeLocation = placeResponse.getData().getLocation(); // Find all cities/towns within 50 miles of this location. PopulatedPlacesResponse placesResponse = geoDbApi.findPlaces( FindPlacesRequest.builder() .nearLocation( NearLocationRequest.builder() .latitude(placeLocation.getLatitude()) .longitude(placeLocation.getLongitude()) .radius(50) .radiusUnit(LocationRadiusUnit.MILES) .build()) .minPopulation(50000) .types(Collections.singleton(PlaceRequestType.CITY)) .sort( GeoDbSort.builder() .fields(new SortField[] { new SortField(PlaceSortFields.FindPlaces.POPULATION, true) }) .build()) .build() ) ``` -------------------------------- ### Find Regions (States) in a Country Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Retrieves all regions (states) for a specified country, in this case, the US. ```java RegionsResponse regionsResponse = geoDbApi.findRegions( FindRegionsRequest.builder() .countryId("US") .build() ); ``` -------------------------------- ### Maven Dependency for GeoDB Java Client Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Add this compile-time dependency to your Maven pom.xml to include the GeoDB Java Client library. ```xml <dependency> <groupId>com.wirefreethought.geodb</groupId> <artifactId>geodb-java-client</artifactId> <version>2.1.0</version> </dependency> ``` -------------------------------- ### Calculate Distance Between Two Cities Source: https://github.com/wirefreethought/geodb-java-client/blob/master/README.md Calculates the distance between two specified cities (Los Angeles and Dallas) in miles. ```java DistanceResponse distanceResponse = geoDbApi.getCityDistance( DistanceResponse.builder() .fromCityId("Q65") .toCityId("Q16557") .distanceUnit(DistanceUnit.MILES) .build() ); ```