28 lines
888 B
Java
28 lines
888 B
Java
package SuMoC.backend.geocoding;
|
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
public class NominatimClient implements GeocodingClient {
|
|
|
|
private final WebClient nominatimClient;
|
|
|
|
public NominatimClient(WebClient nominatimClient) {
|
|
this.nominatimClient = nominatimClient;
|
|
}
|
|
|
|
@Override
|
|
public Mono<GeocodingResponse> reverse(double lat, double lon) {
|
|
return nominatimClient.get()
|
|
.uri(uriBuilder -> uriBuilder.path("/reverse")
|
|
.queryParam("lat", lat)
|
|
.queryParam("lon", lon)
|
|
.queryParam("format", "jsonv2")
|
|
.build())
|
|
.retrieve()
|
|
.bodyToMono(ReverseResponse.class)
|
|
.map(response -> new GeocodingResponse(response.address()));
|
|
}
|
|
}
|
|
|