java.lang.Object
com.example.cab302project.OpenStreetMapGeoCoder
- All Implemented Interfaces:
IGeocodingService
Implementation of the geocoding service using OpenStreetMap Nominatim API.
Provides functionality to convert addresses to coordinates, generate
address suggestions, and perform reverse geocoding.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble[]geocodeAddress(String address) Converts an address into latitude and longitude using the Nominatim API.getAddressSuggestions(String query) Retrieves up to 5 address suggestions for the given query using the Nominatim API.reverseGeocode(double lat, double lon) Converts latitude and longitude coordinates into a human-readable address using the OpenStreetMap Nominatim reverse geocoding service.
-
Constructor Details
-
OpenStreetMapGeoCoder
public OpenStreetMapGeoCoder()
-
-
Method Details
-
geocodeAddress
Converts an address into latitude and longitude using the Nominatim API.- Specified by:
geocodeAddressin interfaceIGeocodingService- Parameters:
address- the address string to geocode- Returns:
- a double array where index 0 is latitude and index 1 is longitude
- Throws:
IllegalArgumentException- if the address is not foundException- if the HTTP request fails
-
getAddressSuggestions
Retrieves up to 5 address suggestions for the given query using the Nominatim API.- Specified by:
getAddressSuggestionsin interfaceIGeocodingService- Parameters:
query- the partial address string to search for- Returns:
- a list of matching display name strings, or an empty list if the query is too short
- Throws:
Exception- if the HTTP request fails
-
reverseGeocode
Converts latitude and longitude coordinates into a human-readable address using the OpenStreetMap Nominatim reverse geocoding service.- Specified by:
reverseGeocodein interfaceIGeocodingService- Parameters:
lat- the latitude coordinate to reverse geocodelon- the longitude coordinate to reverse geocode- Returns:
- a readable address string, or a formatted coordinate string if no address is found
- Throws:
Exception- if the HTTP request fails
-