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 double latitude;
25 private final double longitude;
26 private final double altitude;
28 GeoParsedResult(double latitude, double longitude, double altitude) {
29 super(ParsedResultType.GEO);
30 this.latitude = latitude;
31 this.longitude = longitude;
32 this.altitude = altitude;
35 public String getGeoURI() {
36 StringBuffer result = new StringBuffer();
37 result.append("geo:");
38 result.append(latitude);
40 result.append(longitude);
43 result.append(altitude);
45 return result.toString();
49 * @return latitude in degrees
51 public double getLatitude() {
56 * @return longitude in degrees
58 public double getLongitude() {
63 * @return altitude in meters. If not specified, in the geo URI, returns 0.0
65 public double getAltitude() {
69 public String getDisplayResult() {
70 StringBuffer result = new StringBuffer();
71 result.append(latitude);
73 result.append(longitude);
76 result.append(altitude);
79 return result.toString();
83 * @return a URI link to Google Maps which display the point on the Earth described
84 * by this instance, and sets the zoom level in a way that roughly reflects the
85 * altitude, if specified
88 public String getGoogleMapsURI() {
89 StringBuffer result = new StringBuffer(50);
90 result.append("http://maps.google.com/?ll=");
91 result.append(latitude);
93 result.append(longitude);
94 if (altitude > 0.0f) {
95 // Map altitude to zoom level, cleverly. Roughly, zoom level 19 is like a
96 // view from 1000ft, 18 is like 2000ft, 17 like 4000ft, and so on.
97 double altitudeInFeet = altitude * 3.28;
98 int altitudeInKFeet = (int) (altitudeInFeet / 1000.0);
99 // No Math.log() available here, so compute log base 2 the old fashioned way
100 // Here logBaseTwo will take on a value between 0 and 18 actually
102 while (altitudeInKFeet > 1 && logBaseTwo < 18) {
103 altitudeInKFeet >>= 1;
106 int zoom = 19 - logBaseTwo;
107 result.append("&z=");
110 return result.toString();