2 * Copyright 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.result;
22 public final class GeoParsedResult extends ParsedResult {
24 private final String geoURI;
25 private final float latitude;
26 private final float longitude;
27 private final float altitude;
29 GeoParsedResult(String geoURI, float latitude, float longitude, float altitude) {
30 super(ParsedResultType.GEO);
32 this.latitude = latitude;
33 this.longitude = longitude;
34 this.altitude = altitude;
37 public String getGeoURI() {
42 * @return latitude in degrees
44 public float getLatitude() {
49 * @return longitude in degrees
51 public float getLongitude() {
56 * @return altitude in meters. If not specified, in the geo URI, returns 0.0
58 public float getAltitude() {
62 public String getDisplayResult() {
63 StringBuffer result = new StringBuffer(50);
64 result.append(latitude);
65 result.append(" deg N, ");
66 result.append(longitude);
67 result.append(" deg E");
68 if (altitude > 0.0f) {
70 result.append(altitude);
73 return result.toString();
77 * @return a URI link to Google Maps which display the point on the Earth described
78 * by this instance, and sets the zoom level in a way that roughly reflects the
79 * altitude, if specified
82 public String getGoogleMapsURI() {
83 StringBuffer result = new StringBuffer(50);
84 result.append("http://maps.google.com/?ll=");
85 result.append(latitude);
87 result.append(longitude);
88 if (altitude > 0.0f) {
89 // Map altitude to zoom level, cleverly. Roughly, zoom level 19 is like a
90 // view from 1000ft, 18 is like 2000ft, 17 like 4000ft, and so on.
91 float altitudeInFeet = altitude * 3.28f;
92 int altitudeInKFeet = (int) (altitudeInFeet / 1000.0f);
93 // No Math.log() available here, so compute log base 2 the old fashioned way
94 // Here logBaseTwo will take on a value between 0 and 18 actually
96 while (altitudeInKFeet > 1 && logBaseTwo < 18) {
97 altitudeInKFeet >>= 1;
100 int zoom = 19 - logBaseTwo;
101 result.append("&z=");
104 return result.toString();