Parse coordinates from google url
This commit is contained in:
parent
fcf8f94daa
commit
d21386168e
2 changed files with 33 additions and 4 deletions
|
@ -252,7 +252,6 @@ public class GeoPointParserUtil {
|
||||||
}
|
}
|
||||||
final String postf = "\\s\\((\\p{L}|\\p{M}|\\p{Z}|\\p{S}|\\p{N}|\\p{P}|\\p{C})*\\)$";
|
final String postf = "\\s\\((\\p{L}|\\p{M}|\\p{Z}|\\p{S}|\\p{N}|\\p{P}|\\p{C})*\\)$";
|
||||||
opath = opath.replaceAll(postf, "");
|
opath = opath.replaceAll(postf, "");
|
||||||
System.out.println("opath=" + opath);
|
|
||||||
return parseGoogleMapsPath(opath, params);
|
return parseGoogleMapsPath(opath, params);
|
||||||
}
|
}
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
|
@ -262,13 +261,32 @@ public class GeoPointParserUtil {
|
||||||
return new GeoParsedPoint(m.group(1));
|
return new GeoParsedPoint(m.group(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String DATA_PREFIX = "/data=";
|
||||||
String[] pathPrefixes = new String[]{"/@", "/ll=",
|
String[] pathPrefixes = new String[]{"/@", "/ll=",
|
||||||
"loc:", "/"};
|
"loc:", DATA_PREFIX, "/"};
|
||||||
for (String pref : pathPrefixes) {
|
for (String pref : pathPrefixes) {
|
||||||
if (path.contains(pref)) {
|
if (path.contains(pref)) {
|
||||||
path = path.substring(path.lastIndexOf(pref) + pref.length());
|
path = path.substring(path.lastIndexOf(pref) + pref.length());
|
||||||
return parseGoogleMapsPath(path, params);
|
if (path.contains("/")) {
|
||||||
|
path = path.substring(0, path.indexOf('/'));
|
||||||
|
}
|
||||||
|
if (pref.equals(DATA_PREFIX)) {
|
||||||
|
String[] vls = path.split("!");
|
||||||
|
String lat = null;
|
||||||
|
String lon = null;
|
||||||
|
for (String v : vls) {
|
||||||
|
if (v.startsWith("3d")) {
|
||||||
|
lat = v.substring(2);
|
||||||
|
} else if (v.startsWith("4d")) {
|
||||||
|
lon = v.substring(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lat != null && lon != null) {
|
||||||
|
return new GeoParsedPoint(Double.valueOf(lat), Double.valueOf(lon));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return parseGoogleMapsPath(path, params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (host.endsWith(".amap.com")) {
|
} else if (host.endsWith(".amap.com")) {
|
||||||
|
|
|
@ -32,6 +32,17 @@ public class GeoPointParserUtilTest {
|
||||||
System.out.println(actual);
|
System.out.println(actual);
|
||||||
assertGeoPoint(actual, new GeoParsedPoint(46.853582, 9.529903));
|
assertGeoPoint(actual, new GeoParsedPoint(46.853582, 9.529903));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGoogleMapsData() {
|
||||||
|
// https://www.google.com/maps?daddr=Bahnhofplatz+3,+7000+Chur@46.853582,9.529903
|
||||||
|
GeoParsedPoint actual = GeoPointParserUtil.parse(
|
||||||
|
"https://www.google.co.in/maps/place/10%C2%B007'16.8%22N+76%C2%B020'54.2%22E/@10.1213253,76.3478427,247m/data=!3m2!1e3!4b1!4m6!3m5!1s0x0:0x0!7e2!8m2!3d10.1213237!4d76.348392?shorturl=1");
|
||||||
|
assertGeoPoint(actual, new GeoParsedPoint(10.1213253, 76.3478427));
|
||||||
|
actual = GeoPointParserUtil.parse(
|
||||||
|
"https://www.google.co.in/maps/place/data=!3m2!1e3!4b1!4m6!3m5!1s0x0:0x0!7e2!8m2!3d10.1213237!4d76.348392?shorturl=1");
|
||||||
|
assertGeoPoint(actual, new GeoParsedPoint(10.1213237, 76.348392));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGeoPoint() {
|
public void testGeoPoint() {
|
||||||
|
|
Loading…
Reference in a new issue