Fixed a bug in geo coordinate display, where we were always tacking on "deg N" and...
[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 String geoURI;
25   private final float latitude;
26   private final float longitude;
27   private final float altitude;
28
29   GeoParsedResult(String geoURI, float latitude, float longitude, float altitude) {
30     super(ParsedResultType.GEO);
31     this.geoURI = geoURI;
32     this.latitude = latitude;
33     this.longitude = longitude;
34     this.altitude = altitude;
35   }
36
37   public String getGeoURI() {
38     return geoURI;
39   }
40
41   /**
42    * @return latitude in degrees
43    */
44   public float getLatitude() {
45     return latitude;
46   }
47
48   /**
49    * @return longitude in degrees
50    */
51   public float getLongitude() {
52     return longitude;
53   }
54
55   /**
56    * @return altitude in meters. If not specified, in the geo URI, returns 0.0
57    */
58   public float getAltitude() {
59     return altitude;
60   }
61
62   public String getDisplayResult() {
63     StringBuffer result = new StringBuffer(50);
64     result.append(latitude);
65     result.append(", ");
66     result.append(longitude);
67     if (altitude > 0.0f) {
68       result.append(", ");
69       result.append(altitude);
70       result.append('m');
71     }
72     return result.toString();
73   }
74
75   /**
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
79    */
80   /*
81   public String getGoogleMapsURI() {
82     StringBuffer result = new StringBuffer(50);
83     result.append("http://maps.google.com/?ll=");
84     result.append(latitude);
85     result.append(',');
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
94       int logBaseTwo = 0;
95       while (altitudeInKFeet > 1 && logBaseTwo < 18) {
96         altitudeInKFeet >>= 1;
97         logBaseTwo++;
98       }
99       int zoom = 19 - logBaseTwo;
100       result.append("&z=");
101       result.append(zoom);
102     }
103     return result.toString();
104   }
105    */
106
107 }