Remove my old email address from files. Might as well save spammers the trouble.
[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(" deg N, ");
66     result.append(longitude);
67     result.append(" deg E");
68     if (altitude > 0.0f) {
69       result.append(", ");
70       result.append(altitude);
71       result.append('m');
72     }
73     return result.toString();
74   }
75
76   /**
77    * @return a URI link to Google Maps which display the point on the Earth described
78    *  by this instance, and sets the zoom level in a way that roughly reflects the
79    *  altitude, if specified
80    */
81   /*
82   public String getGoogleMapsURI() {
83     StringBuffer result = new StringBuffer(50);
84     result.append("http://maps.google.com/?ll=");
85     result.append(latitude);
86     result.append(',');
87     result.append(longitude);
88     if (altitude > 0.0f) {
89       // Map altitude to zoom level, cleverly. Roughly, zoom level 19 is like a
90       // view from 1000ft, 18 is like 2000ft, 17 like 4000ft, and so on.
91       float altitudeInFeet = altitude * 3.28f;
92       int altitudeInKFeet = (int) (altitudeInFeet / 1000.0f);
93       // No Math.log() available here, so compute log base 2 the old fashioned way
94       // Here logBaseTwo will take on a value between 0 and 18 actually
95       int logBaseTwo = 0;
96       while (altitudeInKFeet > 1 && logBaseTwo < 18) {
97         altitudeInKFeet >>= 1;
98         logBaseTwo++;
99       }
100       int zoom = 19 - logBaseTwo;
101       result.append("&z=");
102       result.append(zoom);
103     }
104     return result.toString();
105   }
106    */
107
108 }