-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentView.swift
224 lines (140 loc) · 6.12 KB
/
ContentView.swift
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//
// ContentView.swift
// GPS
//
// Created by JP MBP on 3/25/22.
//
import SwiftUI
extension String{
func load() ->UIImage {
do{
//string to URL
guard let url = URL(string: self) else{
//empty image if wrong url>>>>>>>>>>>>
return UIImage()
}
//url to data
let data : Data = try Data(contentsOf: url)
//create uuimage obj from data
return UIImage(data: data) ?? UIImage()
}catch{
}
return UIImage()
}
}
//@State var zoomsrt : String
struct ContentView: View {
@State private var quoteData: QuoteData? = QuoteData( lat: "21.06268",long: "86.84669") // parada 2 anahuac
//parada 1 anahuac 21.06227, -86.84641
@State var state = ""
@State var apiURL = ""
//@State var convertedValueRaw: String = "2.0"
//switch case
@State private var tiempo = "4:32"
@State var zoom = 16.0
var body: some View {
ZStack{
VStack{
Text(" GPS").bold()
.foregroundColor(.red)
.fontWeight(.heavy)
.font(.title)
Text("Tiempo estimado de llegada : 4:32")
Text(quoteData?.lat ?? "latitude")
Text(quoteData?.long ?? "longitude")
Slider(value: $zoom, in: 10...20)
Spacer()
if let lat = quoteData?.lat, let long = quoteData?.long {
var hola = zooming(zoom: zoom)
//let zoomstr = String(zoom)
Spacer()
Image(uiImage: "https://maps.googleapis.com/maps/api/staticmap?center=\(lat),\(long)&zoom=\(hola)&maptype=hybrid&size=400x400&key=НЩГКЛУНРУКУ&markers=\(lat),\(long)".load())
.resizable()
.frame(width: 400, height: 400)
}
Spacer()
Button("Track") {
loadData()
textintro()
}
.frame(width: 100, height: 100)
.foregroundColor(.gray)
.background(Color.blue)
.font(.title)
}
}
.padding()
}
func textintro(){
self.state = "Localizando ..."
}
private func loadData(){
guard let url = URL(string: "http://172.20.17.206/cordenadas.json") else{
return
}
URLSession.shared.dataTask(with: url){data , response, error in
guard let data = data else{
return
}
if let decodedData = try? JSONDecoder().decode(QuoteData.self, from: data){
DispatchQueue.main.async {
self.quoteData = decodedData
}
}
}.resume()
}
}
func zooming(zoom :Double) ->String{
@State var zoomsrt : String
//Int(zoom)
switch Int(zoom) {
case 10:
zoomsrt = "10"
return zoomsrt
case 11:
zoomsrt = "11"
return zoomsrt
case 12:
zoomsrt = "12"
return zoomsrt
case 13:
zoomsrt = "13"
return zoomsrt
case 14:
zoomsrt = "14"
return zoomsrt
case 15:
zoomsrt = "15"
return zoomsrt
case 16:
zoomsrt = "16"
return zoomsrt
case 17:
zoomsrt = "17"
return zoomsrt
case 18:
zoomsrt = "18"
return zoomsrt
case 19:
zoomsrt = "19"
return zoomsrt
case 20:
zoomsrt = "20"
return zoomsrt
case 21:
zoomsrt = "21"
return zoomsrt
default:
zoomsrt = "16"
return zoomsrt
}
}
struct QuoteData: Decodable{
var lat: String
var long: String
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}