Skip to content

Commit cff96dc

Browse files
committed
Add support for non-dot-decimal-mark locales. Fixes #1
1 parent 2031ac1 commit cff96dc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/org/microg/nlp/backend/nominatim/BackendService.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.location.Address;
55
import android.os.Build;
66
import android.util.Log;
7+
78
import org.json.JSONException;
89
import org.json.JSONObject;
910
import org.microg.nlp.api.GeocoderBackendService;
@@ -20,8 +21,10 @@
2021

2122
public class BackendService extends GeocoderBackendService {
2223
private static final String TAG = BackendService.class.getName();
24+
private static final String SERVICE_URL_MAPQUEST = "http://open.mapquestapi.com/nominatim/v1/";
25+
private static final String SERVICE_URL_OSM = " http://nominatim.openstreetmap.org/";
2326
private static final String REVERSE_GEOCODE_URL =
24-
"http://open.mapquestapi.com/nominatim/v1/reverse?format=json&accept-language=%s&lat=%f&lon=%f";
27+
"%sreverse?format=json&accept-language=%s&lat=%f&lon=%f";
2528
private static final String WIRE_LATITUDE = "lat";
2629
private static final String WIRE_LONGITUDE = "lon";
2730
private static final String WIRE_ADDRESS = "address";
@@ -38,8 +41,9 @@ public class BackendService extends GeocoderBackendService {
3841

3942
@Override
4043
protected List<Address> getFromLocation(double latitude, double longitude, int maxResults,
41-
String locale) {
42-
String url = String.format(REVERSE_GEOCODE_URL, locale.split("_")[0], latitude, longitude);
44+
String locale) {
45+
String url = String.format(Locale.US, REVERSE_GEOCODE_URL, SERVICE_URL_MAPQUEST,
46+
locale.split("_")[0], latitude, longitude);
4347
try {
4448
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
4549
setUserAgentOnConnection(connection);
@@ -52,9 +56,7 @@ protected List<Address> getFromLocation(double latitude, double longitude, int m
5256
addresses.add(address);
5357
return addresses;
5458
}
55-
} catch (IOException e) {
56-
Log.w(TAG, e);
57-
} catch (JSONException e) {
59+
} catch (IOException | JSONException e) {
5860
Log.w(TAG, e);
5961
}
6062
return null;
@@ -102,8 +104,8 @@ private static Locale localeFromLocaleString(String localeString) {
102104

103105
@Override
104106
protected List<Address> getFromLocationName(String locationName, int maxResults,
105-
double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude,
106-
double upperRightLongitude, String locale) {
107+
double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude,
108+
double upperRightLongitude, String locale) {
107109
return null;
108110
}
109111

0 commit comments

Comments
 (0)