Skip to content

Commit aae4712

Browse files
committed
Add small example
1 parent 687665e commit aae4712

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Dialog/Helper/MapExamplesViewModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import GoogleMaps
1717
class MapExamplesViewModel: ObservableObject {
1818

1919
@Published var examples: [MapExample] = [
20+
MapExample(
21+
title: "Basic panorama",
22+
description: "A simple panorama. Shows how to initalize and present a panorama.",
23+
destination: AnyView(BasicPanorama())
24+
),
2025
MapExample(
2126
title: "Basic map",
2227
description: "A simple map. Shows how to initalize and update map options.",
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright 2024 Google LLC. All rights reserved.
2+
//
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5+
// file except in compliance with the License. You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software distributed under
10+
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
// ANY KIND, either express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
import SwiftUI
15+
import GoogleMaps
16+
17+
struct BasicPanorama: View {
18+
19+
let viewModel = PanoramaViewModel()
20+
let newYork = CLLocationCoordinate2D(latitude: 40.7230260, longitude: -73.9988390)
21+
22+
var body: some View {
23+
ZStack {
24+
PanoramaView(viewModel: viewModel)
25+
.task {
26+
viewModel.move(near: newYork)
27+
}
28+
}
29+
}
30+
}
31+
32+
// MARK: - ViewModel
33+
34+
class PanoramaViewModel: NSObject, ObservableObject {
35+
36+
let panoramaView: GMSPanoramaView = {
37+
let panoramaView = GMSPanoramaView()
38+
return panoramaView
39+
}()
40+
41+
override init() {
42+
super.init()
43+
panoramaView.delegate = self
44+
}
45+
46+
func move(near coordinate: CLLocationCoordinate2D) {
47+
panoramaView.moveNearCoordinate(coordinate)
48+
}
49+
50+
func move(to panoramaID: String) {
51+
panoramaView.move(toPanoramaID: panoramaID)
52+
}
53+
}
54+
55+
extension PanoramaViewModel: GMSPanoramaViewDelegate {
56+
func panoramaView(_ panoramaView: GMSPanoramaView, didMoveTo panorama: GMSPanorama?) {
57+
let panoramaID = panorama?.panoramaID ?? "Unknown"
58+
print("Did move to panorama: \(panoramaID)")
59+
}
60+
61+
func panoramaView(_ view: GMSPanoramaView, didMoveTo panorama: GMSPanorama, nearCoordinate coordinate: CLLocationCoordinate2D) {
62+
print("Did move to panorama: \(panorama.panoramaID) near coordinate: \(coordinate)")
63+
}
64+
65+
func panoramaViewDidStartRendering(_ panoramaView: GMSPanoramaView) {
66+
print("Panorama view started rendering")
67+
}
68+
69+
func panoramaViewDidFinishRendering(_ panoramaView: GMSPanoramaView) {
70+
print("Panorama did finish rendering")
71+
}
72+
73+
func panoramaView(_ view: GMSPanoramaView, error: any Error, onMoveNearCoordinate coordinate: CLLocationCoordinate2D) {
74+
print("Failed to move to coordinate: \(coordinate)")
75+
}
76+
77+
func panoramaView(_ view: GMSPanoramaView, error: any Error, onMoveToPanoramaID panoramaID: String) {
78+
print("Failed to move to panoramaID: \(panoramaID)")
79+
}
80+
}
81+
82+
// MARK: - UIViewRepresentable
83+
84+
struct PanoramaView: UIViewRepresentable {
85+
let viewModel: PanoramaViewModel
86+
87+
init(viewModel: PanoramaViewModel) {
88+
self.viewModel = viewModel
89+
}
90+
91+
func makeUIView(context: Context) -> GMSPanoramaView {
92+
return viewModel.panoramaView
93+
}
94+
95+
func updateUIView(_ uiView: GMSPanoramaView, context: Context) {}
96+
}
97+
98+

0 commit comments

Comments
 (0)