mirror of
https://github.com/traccar/traccar.git
synced 2025-01-08 11:47:49 +08:00
Add Open Location Code geocoder
This commit is contained in:
parent
9a285e59e5
commit
3d793f502e
@ -90,6 +90,7 @@ dependencies {
|
||||
implementation "com.nimbusds:oauth2-oidc-sdk:11.10.1"
|
||||
implementation "com.rabbitmq:amqp-client:5.20.0"
|
||||
implementation "com.warrenstrange:googleauth:1.5.0"
|
||||
implementation 'com.google.openlocationcode:openlocationcode:1.0.4'
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
testImplementation "org.mockito:mockito-core:5.11.0"
|
||||
|
@ -10,7 +10,7 @@
|
||||
<entry key='web.debug'>true</entry>
|
||||
<entry key='web.console'>true</entry>
|
||||
|
||||
<entry key='geocoder.type'>test</entry>
|
||||
<entry key='geocoder.type'>pluscodes</entry>
|
||||
|
||||
<entry key='media.path'>./target/media</entry>
|
||||
|
||||
|
@ -66,7 +66,7 @@ import org.traccar.geocoder.MapmyIndiaGeocoder;
|
||||
import org.traccar.geocoder.NominatimGeocoder;
|
||||
import org.traccar.geocoder.OpenCageGeocoder;
|
||||
import org.traccar.geocoder.PositionStackGeocoder;
|
||||
import org.traccar.geocoder.TestGeocoder;
|
||||
import org.traccar.geocoder.PlusCodesGeocoder;
|
||||
import org.traccar.geocoder.TomTomGeocoder;
|
||||
import org.traccar.geolocation.GeolocationProvider;
|
||||
import org.traccar.geolocation.GoogleGeolocationProvider;
|
||||
@ -211,8 +211,8 @@ public class MainModule extends AbstractModule {
|
||||
int cacheSize = config.getInteger(Keys.GEOCODER_CACHE_SIZE);
|
||||
Geocoder geocoder;
|
||||
switch (type) {
|
||||
case "test":
|
||||
geocoder = new TestGeocoder();
|
||||
case "pluscodes":
|
||||
geocoder = new PlusCodesGeocoder();
|
||||
break;
|
||||
case "nominatim":
|
||||
geocoder = new NominatimGeocoder(client, url, key, language, cacheSize, addressFormat);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2022 Anton Tananaev (anton@traccar.org)
|
||||
* Copyright 2022 - 2024 Anton Tananaev (anton@traccar.org)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.traccar.geocoder;
|
||||
|
||||
import com.google.openlocationcode.OpenLocationCode;
|
||||
import org.traccar.database.StatisticsManager;
|
||||
|
||||
public class TestGeocoder implements Geocoder {
|
||||
public class PlusCodesGeocoder implements Geocoder {
|
||||
|
||||
@Override
|
||||
public void setStatisticsManager(StatisticsManager statisticsManager) {
|
||||
@ -25,7 +26,7 @@ public class TestGeocoder implements Geocoder {
|
||||
|
||||
@Override
|
||||
public String getAddress(double latitude, double longitude, ReverseGeocoderCallback callback) {
|
||||
String address = String.format("Location %f, %f", latitude, longitude);
|
||||
String address = new OpenLocationCode(latitude, longitude).getCode();
|
||||
if (callback != null) {
|
||||
callback.onSuccess(address);
|
||||
return null;
|
Loading…
Reference in New Issue
Block a user