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);
66 result.append(longitude);
67 if (altitude > 0.0f) {
69 result.append(altitude);
72 return result.toString();
76 * @return a URI link to Google Maps which display the point on the Earth described
77 * by this instance, and sets the zoom level in a way that roughly reflects the
78 * altitude, if specified
81 public String getGoogleMapsURI() {
82 StringBuffer result = new StringBuffer(50);
83 result.append("http://maps.google.com/?ll=");
84 result.append(latitude);
86 result.append(longitude);
87 if (altitude > 0.0f) {
88 // Map altitude to zoom level, cleverly. Roughly, zoom level 19 is like a
89 // view from 1000ft, 18 is like 2000ft, 17 like 4000ft, and so on.
90 float altitudeInFeet = altitude * 3.28f;
91 int altitudeInKFeet = (int) (altitudeInFeet / 1000.0f);
92 // No Math.log() available here, so compute log base 2 the old fashioned way
93 // Here logBaseTwo will take on a value between 0 and 18 actually
95 while (altitudeInKFeet > 1 && logBaseTwo < 18) {
96 altitudeInKFeet >>= 1;
99 int zoom = 19 - logBaseTwo;
100 result.append("&z=");
103 return result.toString();