Slight refinement to last change - a cached row which
[zxing.git] / core / src / com / google / zxing / client / result / GeoParsedResult.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.result;
18
19 /**
20  * @author Sean Owen
21  */
22 public final class GeoParsedResult extends ParsedResult {
23
24   private final double latitude;
25   private final double longitude;
26   private final double altitude;
27
28   GeoParsedResult(double latitude, double longitude, double altitude) {
29     super(ParsedResultType.GEO);
30     this.latitude = latitude;
31     this.longitude = longitude;
32     this.altitude = altitude;
33   }
34
35   public String getGeoURI() {
36     StringBuffer result = new StringBuffer();
37     result.append("geo:");
38     result.append(latitude);
39     result.append(',');
40     result.append(longitude);
41     if (altitude > 0) {
42       result.append(',');
43       result.append(altitude);
44     }
45     return result.toString();
46   }
47
48   /**
49    * @return latitude in degrees
50    */
51   public double getLatitude() {
52     return latitude;
53   }
54
55   /**
56    * @return longitude in degrees
57    */
58   public double getLongitude() {
59     return longitude;
60   }
61
62   /**
63    * @return altitude in meters. If not specified, in the geo URI, returns 0.0
64    */
65   public double getAltitude() {
66     return altitude;
67   }
68
69   public String getDisplayResult() {
70     StringBuffer result = new StringBuffer();
71     result.append(latitude);
72     result.append(", ");
73     result.append(longitude);
74     if (altitude > 0.0) {
75       result.append(", ");
76       result.append(altitude);
77       result.append('m');
78     }
79     return result.toString();
80   }
81
82   /**
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
86    */
87   /*
88   public String getGoogleMapsURI() {
89     StringBuffer result = new StringBuffer(50);
90     result.append("http://maps.google.com/?ll=");
91     result.append(latitude);
92     result.append(',');
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
101       int logBaseTwo = 0;
102       while (altitudeInKFeet > 1 && logBaseTwo < 18) {
103         altitudeInKFeet >>= 1;
104         logBaseTwo++;
105       }
106       int zoom = 19 - logBaseTwo;
107       result.append("&z=");
108       result.append(zoom);
109     }
110     return result.toString();
111   }
112    */
113
114 }