Skip to content

Commit

Permalink
fix negative coordinates parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Mar 3, 2020
1 parent f4c6b96 commit 9e9189c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/truchsess/send2car/geo/GeoUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void fromGeoUri(final Uri uri) {
final String resource = qpos < 0 ? data : data.substring(0, qpos);
final String query = data.substring(qpos+1);

final 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;
Expand All @@ -75,7 +75,7 @@ public void fromGeoUri(final Uri uri) {
if (paramMatcher.matches()) {
final String q0 = paramMatcher.group(1);
final String q1 = q0.replaceAll("[\\n\\r\\t\\f]",", ");
final 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));
Expand All @@ -98,7 +98,7 @@ public void fromHttpUri(final Uri uri) {
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);
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));
Expand Down

0 comments on commit 9e9189c

Please sign in to comment.