This commit is contained in:
Victor Shcherb 2016-10-19 19:14:45 +02:00
parent 16f2d74a53
commit f4927f44e1

View file

@ -85,6 +85,12 @@ public class GeoPointParserUtil {
assertUrlEquals(url, actual.getGeoUriString()); assertUrlEquals(url, actual.getGeoUriString());
assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon)); assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon));
// google.navigation:q=34.99393,-106.61568
url = "google.navigation:q=" + dlat + "," + dlon;
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon));
// geo:34.99393,-106.61568 // geo:34.99393,-106.61568
url = "geo:" + dlat + "," + dlon; url = "geo:" + dlat + "," + dlon;
System.out.println("url: " + url); System.out.println("url: " + url);
@ -92,6 +98,7 @@ public class GeoPointParserUtil {
assertUrlEquals(url, actual.getGeoUriString()); assertUrlEquals(url, actual.getGeoUriString());
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon)); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon));
// geo:34.99393,-106.61568?z=11 // geo:34.99393,-106.61568?z=11
z = 11; z = 11;
url = "geo:" + dlat + "," + dlon + "?z=" + z; url = "geo:" + dlat + "," + dlon + "?z=" + z;
@ -852,12 +859,23 @@ public class GeoPointParserUtil {
else else
scheme = scheme.toLowerCase(Locale.US); scheme = scheme.toLowerCase(Locale.US);
if ("http".equals(scheme) || "https".equals(scheme)) { if ("http".equals(scheme) || "https".equals(scheme) || "google.navigation".equals(scheme)) {
String host = uri.getHost(); String host = uri.getHost();
if (host == null) Map<String, String> params = getQueryParameters(uri);
if("google.navigation".equals(scheme)) {
host = scheme;
if(uri.getSchemeSpecificPart() == null) {
return null; return null;
else } else if(!uri.getSchemeSpecificPart().contains("=")) {
params = getQueryParameters("q="+uri.getSchemeSpecificPart());
} else {
params = getQueryParameters(uri.getSchemeSpecificPart());
}
} else if (host == null) {
return null;
} else {
host = host.toLowerCase(Locale.US); host = host.toLowerCase(Locale.US);
}
String path = uri.getPath(); String path = uri.getPath();
if (path == null) { if (path == null) {
path = ""; path = "";
@ -914,7 +932,6 @@ public class GeoPointParserUtil {
} else if (host.startsWith("map.baidu.")) { // .com and .cn both work } else if (host.startsWith("map.baidu.")) { // .com and .cn both work
/* Baidu Map uses a custom format for lat/lon., it is basically standard lat/lon /* Baidu Map uses a custom format for lat/lon., it is basically standard lat/lon
* multiplied by 100,000, then rounded to an integer */ * multiplied by 100,000, then rounded to an integer */
Map<String, String> params = getQueryParameters(uri);
String zm = params.get("l"); String zm = params.get("l");
String[] vls = silentSplit(params.get("c"), ","); String[] vls = silentSplit(params.get("c"), ",");
if (vls != null && vls.length >= 2) { if (vls != null && vls.length >= 2) {
@ -924,7 +941,6 @@ public class GeoPointParserUtil {
return new GeoParsedPoint(lat, lon, zoom); return new GeoParsedPoint(lat, lon, zoom);
} }
} else if (simpleDomains.contains(host)) { } else if (simpleDomains.contains(host)) {
Map<String, String> params = getQueryParameters(uri);
if (uri.getQuery() == null && params.size() == 0) { if (uri.getQuery() == null && params.size() == 0) {
// DOUBLE check this may be wrong test of openstreetmap.de (looks very weird url and server doesn't respond) // DOUBLE check this may be wrong test of openstreetmap.de (looks very weird url and server doesn't respond)
params = getQueryParameters(path.substring(1)); params = getQueryParameters(path.substring(1));
@ -941,7 +957,6 @@ public class GeoPointParserUtil {
return new GeoParsedPoint(lat, lon, zoom); return new GeoParsedPoint(lat, lon, zoom);
} }
} else if (host.matches("(?:www\\.)?(?:maps\\.)?yandex\\.[a-z]+")) { } else if (host.matches("(?:www\\.)?(?:maps\\.)?yandex\\.[a-z]+")) {
Map<String, String> params = getQueryParameters(uri);
String ll = params.get("ll"); String ll = params.get("ll");
if (ll != null) { if (ll != null) {
Matcher matcher = commaSeparatedPairPattern.matcher(ll); Matcher matcher = commaSeparatedPairPattern.matcher(ll);
@ -954,7 +969,7 @@ public class GeoPointParserUtil {
String latString = null; String latString = null;
String lonString = null; String lonString = null;
String z = String.valueOf(GeoParsedPoint.NO_ZOOM); String z = String.valueOf(GeoParsedPoint.NO_ZOOM);
Map<String, String> params = getQueryParameters(uri);
if (params.containsKey("q")) { if (params.containsKey("q")) {
System.out.println("q=" + params.get("q")); System.out.println("q=" + params.get("q"));
Matcher matcher = commaSeparatedPairPattern.matcher(params.get("q")); Matcher matcher = commaSeparatedPairPattern.matcher(params.get("q"));
@ -1033,7 +1048,6 @@ public class GeoPointParserUtil {
} }
} }
} else if (host.equals("here.com") || host.endsWith(".here.com")) { // www.here.com, share.here.com, here.com } else if (host.equals("here.com") || host.endsWith(".here.com")) { // www.here.com, share.here.com, here.com
Map<String, String> params = getQueryParameters(uri);
String z = String.valueOf(GeoParsedPoint.NO_ZOOM); String z = String.valueOf(GeoParsedPoint.NO_ZOOM);
String label = null; String label = null;
if (params.containsKey("msg")) { if (params.containsKey("msg")) {
@ -1058,7 +1072,6 @@ public class GeoPointParserUtil {
} }
} }
} else if (host.endsWith(".qq.com")) { } else if (host.endsWith(".qq.com")) {
Map<String, String> params = getQueryParameters(uri);
String x = null; String x = null;
String y = null; String y = null;
String z = String.valueOf(GeoParsedPoint.NO_ZOOM); String z = String.valueOf(GeoParsedPoint.NO_ZOOM);
@ -1112,7 +1125,6 @@ public class GeoPointParserUtil {
return new GeoParsedPoint(y, x, z, label); return new GeoParsedPoint(y, x, z, label);
} else if (host.equals("maps.apple.com")) { } else if (host.equals("maps.apple.com")) {
// https://developer.apple.com/library/iad/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html // https://developer.apple.com/library/iad/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
Map<String, String> params = getQueryParameters(uri);
String z = String.valueOf(GeoParsedPoint.NO_ZOOM); String z = String.valueOf(GeoParsedPoint.NO_ZOOM);
String label = null; String label = null;
if (params.containsKey("q")) { if (params.containsKey("q")) {