-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2c09ff
commit 7978dad
Showing
4 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
/app/build | ||
/app/release | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import java.util.regex.Pattern; | ||
|
||
/********************************************************************************************** | ||
Copyright (C) 2018 Norbert Truchsess [email protected] | ||
Copyright (C) 2020 Norbert Truchsess [email protected] | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -37,34 +37,45 @@ public GeoUrl(final double lat, final double lon, final String description) { | |
this.description = description; | ||
} | ||
|
||
public void fromUri(Uri uri) { | ||
public void fromUri(final Uri uri) { | ||
|
||
String data = uri.getSchemeSpecificPart(); | ||
final String scheme = uri.getScheme(); | ||
|
||
if (scheme.equals("geo") || scheme.equals("google.navigation")) { | ||
fromGeoUri(uri); | ||
} else if (scheme.equals("http") || scheme.equals("https")) { | ||
fromHttpUri(uri); | ||
} | ||
} | ||
|
||
public void fromGeoUri(final Uri uri) { | ||
|
||
final String data = uri.getSchemeSpecificPart(); | ||
|
||
// format is: | ||
// <lat>,<lon>?z=<zoom> | ||
// 0,0?q=<lat>,<lon>(label) | ||
|
||
int qpos = data.indexOf("?"); | ||
String resource = qpos < 0 ? data : data.substring(0, qpos); | ||
String query = data.substring(qpos+1); | ||
final String resource = qpos < 0 ? data : data.substring(0, qpos); | ||
final String query = data.substring(qpos+1); | ||
|
||
Matcher resMatcher = Pattern.compile("^(\\d++\\.?\\d*),(\\d++\\.?\\d*)$").matcher(resource); | ||
final Matcher resMatcher = Pattern.compile("^(\\d++\\.?\\d*),(\\d++\\.?\\d*)$").matcher(resource); | ||
boolean resMatches = resMatcher.matches(); | ||
|
||
lat = resMatches ? Double.parseDouble(resMatcher.group(1)) : Double.NaN; | ||
lon = resMatches ? Double.parseDouble(resMatcher.group(2)) : Double.NaN; | ||
|
||
description = null; | ||
|
||
StringTokenizer queryTokenizer = new StringTokenizer(query,"&"); | ||
final StringTokenizer queryTokenizer = new StringTokenizer(query,"&"); | ||
while (queryTokenizer.hasMoreTokens()) { | ||
final String nextToken = queryTokenizer.nextToken(); | ||
Matcher paramMatcher = Pattern.compile("^q=(.*)$",Pattern.DOTALL).matcher(nextToken); | ||
final Matcher paramMatcher = Pattern.compile("^q=(.*)$",Pattern.DOTALL).matcher(nextToken); | ||
if (paramMatcher.matches()) { | ||
final String q0 = paramMatcher.group(1); | ||
final String q1 = q0.replaceAll("[\\n\\r\\t\\f]",", "); | ||
Matcher locationMatcher = Pattern.compile("^(\\d++\\.?\\d*),(\\d++\\.?\\d*)(\\((.*)\\)|)+$").matcher(q1); | ||
final Matcher locationMatcher = Pattern.compile("^(\\d++\\.?\\d*),(\\d++\\.?\\d*)(\\((.*)\\)|)+$").matcher(q1); | ||
if (locationMatcher.matches()) { | ||
lat = Double.parseDouble(locationMatcher.group(1)); | ||
lon = Double.parseDouble(locationMatcher.group(2)); | ||
|
@@ -77,6 +88,25 @@ public void fromUri(Uri uri) { | |
} | ||
} | ||
|
||
public void fromHttpUri(final Uri uri) { | ||
// formats of google-maps uris: | ||
// https://www.google.com/maps?q=<description>&ll=<lat>,<lon> | ||
// https://maps.google.com/?q=<description>&ll=<lat>,<lon> | ||
// https://www.google.com/maps/@<lat>,<lon>,<zoom>z | ||
|
||
if (uri.getHost().contains("google")) { | ||
description = uri.getQueryParameter("q"); | ||
final String ll = uri.getQueryParameter("ll"); | ||
if (ll != null && !ll.isEmpty()) { | ||
final Matcher locationMatcher = Pattern.compile("^(\\d++\\.?\\d*),(\\d++\\.?\\d*)$").matcher(ll); | ||
if (locationMatcher.matches()) { | ||
lat = Double.parseDouble(locationMatcher.group(1)); | ||
lon = Double.parseDouble(locationMatcher.group(2)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public boolean isValid() { | ||
return !Double.isNaN(lat) && !Double.isNaN(lon); | ||
} | ||
|