This commit is contained in:
Victor Shcherb 2018-12-11 21:20:21 +01:00
parent b916b5b2ec
commit 29215cdc44
3 changed files with 36 additions and 8 deletions

View file

@ -194,7 +194,6 @@ public class Way extends Entity {
}
if (nodeIds != null) {
nodeIds.reverse();
;
}
}
}

View file

@ -526,11 +526,20 @@ public class GeoPointParserUtil {
if (params.containsKey("z")) {
zmPart = params.get("z");
}
String[] vls = silentSplit(path, ",");
String[] vls = null;
if(path.contains("@")) {
path = path.substring(path.indexOf("@") + 1);
if(path.contains(",")) {
vls = silentSplit(path, ",");
}
}
if(vls == null) {
vls = silentSplit(path, ",");
}
if (vls.length >= 2) {
double lat = parseSilentDouble(vls[0]);
double lon = parseSilentDouble(vls[1]);
double lat = parseSilentDouble(vls[0], Double.NaN);
double lon = parseSilentDouble(vls[1], Double.NaN);
int zoom = GeoParsedPoint.NO_ZOOM;
if (vls.length >= 3 || zmPart.length() > 0) {
if (zmPart.length() == 0) {
@ -543,8 +552,10 @@ public class GeoPointParserUtil {
}
zoom = parseZoom(zmPart);
}
if(!Double.isNaN(lat) && !Double.isNaN(lon)) {
return new GeoParsedPoint(lat, lon, zoom);
}
}
return new GeoParsedPoint(URLDecoder.decode(opath));
}
@ -566,13 +577,17 @@ public class GeoPointParserUtil {
}
private static double parseSilentDouble(String zoom) {
return parseSilentDouble(zoom, 0);
}
private static double parseSilentDouble(String zoom, double vl) {
try {
if (zoom != null) {
return Double.valueOf(zoom);
}
} catch (NumberFormatException e) {
}
return 0;
return vl;
}
private static int parseSilentInt(String zoom) {
@ -739,8 +754,9 @@ public class GeoPointParserUtil {
@Override
public String toString() {
return isGeoPoint() ? "GeoParsedPoint [lat=" + lat + ", lon=" + lon + ", zoom=" + zoom
+ ", label=" + label + "]" : "GeoParsedPoint [query=" + query;
return isGeoPoint() ?
String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%d, label=%s]", lat, lon, zoom, label) :
String.format("GeoParsedPoint [query=%s]",query);
}
}
}

View file

@ -20,6 +20,19 @@ public class GeoPointParserUtilTest {
Assert.assertEquals(test.getQuery(), "86HJV99P+29");
}
@Test
public void testGoogleMaps() {
// https://www.google.com/maps?daddr=Bahnhofplatz+3,+7000+Chur@46.853582,9.529903
GeoParsedPoint actual = GeoPointParserUtil.parse(
"https://www.google.com/maps?daddr=Bahnhofplatz+3,+7000+Chur");
assertGeoPoint(actual, new GeoParsedPoint("Bahnhofplatz 3, 7000 Chur"));
actual = GeoPointParserUtil.parse(
"https://www.google.com/maps?daddr=Bahnhofplatz+3,+7000+Chur@46.853582,9.529903");
System.out.println(actual);
assertGeoPoint(actual, new GeoParsedPoint(46.853582, 9.529903));
}
@Test
public void testGeoPoint() {
final int ilat = 34, ilon = -106;