* <a href="http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00">
* http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00</a>.
*
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
*/
final class GeoResultParser extends ResultParser {
public static GeoParsedResult parse(Result result) {
String rawText = result.getText();
- if (rawText == null || !rawText.startsWith("geo:")) {
+ if (rawText == null || (!rawText.startsWith("geo:") && !rawText.startsWith("GEO:"))) {
return null;
}
// Drop geo, query portion
if (latitudeEnd < 0) {
return null;
}
- float latitude = Float.parseFloat(geoURIWithoutQuery.substring(0, latitudeEnd));
- int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);
- float longitude;
- float altitude; // in meters
- if (longitudeEnd < 0) {
- longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1));
- altitude = 0.0f;
- } else {
- longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
- altitude = Float.parseFloat(geoURIWithoutQuery.substring(longitudeEnd + 1));
+ int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);
+ double latitude, longitude, altitude;
+ try {
+ latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));
+ if (longitudeEnd < 0) {
+ longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1));
+ altitude = 0.0;
+ } else {
+ longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
+ altitude = Double.parseDouble(geoURIWithoutQuery.substring(longitudeEnd + 1));
+ }
+ } catch (NumberFormatException nfe) {
+ return null;
}
return new GeoParsedResult(rawText, latitude, longitude, altitude);
}