double latitude = json.getDouble("latitude");
double longitude = json.getDouble("longitude");
String altitudeString = json.optString("altitude");
Double altitude = (altitudeString == null || altitudeString.length() == 0) ? null : Double.parseDouble(altitudeString);
String description = json.optString("description");
return new GeoPoint(latitude, longitude, altitude, description);
} catch (Exception ex) {
Matcher match = GEO_LOCATION_FORMAT.matcher(valueStr);
if (match.find()) {
double latitude = Double.parseDouble(match.group(1).trim());
double longitude = Double.parseDouble(match.group(2).trim());
return new GeoPoint(latitude, longitude);
}
match = GEO_LOCATION_ALTERNATE_FORMAT.matcher(valueStr);
if (match.find()) {
double latitude = Double.parseDouble(match.group(1).trim());
double longitude = Double.parseDouble(match.group(2).trim());
return new GeoPoint(latitude, longitude);
}
throw new RuntimeException("Could not parse location: " + valueStr);
}
}