1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright 2008 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// package com.google.zxing.client.result;
use super::{ParsedRXingResult, ParsedRXingResultType};
/**
* Represents a parsed result that encodes a geographic coordinate, with latitude,
* longitude and altitude.
*
* @author Sean Owen
*/
#[derive(Debug)]
pub struct GeoParsedRXingResult {
latitude: f64,
longitude: f64,
altitude: f64,
query: String,
}
impl ParsedRXingResult for GeoParsedRXingResult {
fn getType(&self) -> super::ParsedRXingResultType {
ParsedRXingResultType::Geo
}
fn getDisplayRXingResult(&self) -> String {
let mut result = String::with_capacity(20);
// result.push_str(self.latitude);
// result.push_str(", ");
// result.push_str(self.longitude);
result.push_str(&format!("{}, {}", self.latitude, self.longitude));
if self.altitude > 0.0 {
result.push_str(&format!(", {}m", self.altitude));
// result.push_str(", ");
// result.push_str(self.altitude);
// result.push('m');
}
if !self.query.is_empty() {
result.push_str(&format!(" ({})", self.query));
// result.push_str(" (");
// result.push_str(self.query);
// result.push(')');
}
result
}
}
impl GeoParsedRXingResult {
pub fn new(latitude: f64, longitude: f64, altitude: f64, query: String) -> Self {
Self {
latitude,
longitude,
altitude,
query,
}
}
pub fn getGeoURI(&self) -> String {
//StringBuilder result = new StringBuilder();
let mut result = format!("geo:{},{}", self.latitude, self.longitude);
// result.append("geo:");
// result.append(latitude);
// result.append(',');
// result.append(longitude);
if self.altitude > 0.0 {
result.push_str(&format!(",{}", self.altitude));
// result.append(',');
// result.append(altitude);
}
if !self.query.is_empty() {
result.push_str(&format!("?{}", self.query));
// result.append('?');
// result.append(query);
}
result
}
/**
* @return latitude in degrees
*/
pub fn getLatitude(&self) -> f64 {
self.latitude
}
/**
* @return longitude in degrees
*/
pub fn getLongitude(&self) -> f64 {
self.longitude
}
/**
* @return altitude in meters. If not specified, in the geo URI, returns 0.0
*/
pub fn getAltitude(&self) -> f64 {
self.altitude
}
/**
* @return query string associated with geo URI or null if none exists
*/
pub fn getQuery(&self) -> &str {
&self.query
}
}
impl PartialEq for GeoParsedRXingResult {
fn eq(&self, other: &Self) -> bool {
self.latitude == other.latitude
&& self.longitude == other.longitude
&& self.altitude == other.altitude
&& self.query == other.query
}
}
impl Eq for GeoParsedRXingResult {}