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;
27 private final String query;
29 GeoParsedResult(double latitude, double longitude, double altitude, String query) {
30 super(ParsedResultType.GEO);
31 this.latitude = latitude;
32 this.longitude = longitude;
33 this.altitude = altitude;
37 public String getGeoURI() {
38 StringBuffer result = new StringBuffer();
39 result.append("geo:");
40 result.append(latitude);
42 result.append(longitude);
45 result.append(altitude);
51 return result.toString();
55 * @return latitude in degrees
57 public double getLatitude() {
62 * @return longitude in degrees
64 public double getLongitude() {
69 * @return altitude in meters. If not specified, in the geo URI, returns 0.0
71 public double getAltitude() {
76 * @return query string associated with geo URI or null if none exists
78 public String getQuery() {
82 public String getDisplayResult() {
83 StringBuffer result = new StringBuffer(20);
84 result.append(latitude);
86 result.append(longitude);
89 result.append(altitude);
97 return result.toString();
101 * @return a URI link to Google Maps which display the point on the Earth described
102 * by this instance, and sets the zoom level in a way that roughly reflects the
103 * altitude, if specified
106 public String getGoogleMapsURI() {
107 StringBuffer result = new StringBuffer(50);
108 result.append("http://maps.google.com/?ll=");
109 result.append(latitude);
111 result.append(longitude);
112 if (altitude > 0.0f) {
113 // Map altitude to zoom level, cleverly. Roughly, zoom level 19 is like a
114 // view from 1000ft, 18 is like 2000ft, 17 like 4000ft, and so on.
115 double altitudeInFeet = altitude * 3.28;
116 int altitudeInKFeet = (int) (altitudeInFeet / 1000.0);
117 // No Math.log() available here, so compute log base 2 the old fashioned way
118 // Here logBaseTwo will take on a value between 0 and 18 actually
120 while (altitudeInKFeet > 1 && logBaseTwo < 18) {
121 altitudeInKFeet >>= 1;
124 int zoom = 19 - logBaseTwo;
125 result.append("&z=");
128 return result.toString();