From 5a711dee1acb4281e23b7dbe61392936675354d5 Mon Sep 17 00:00:00 2001 From: Wayne Bishop Date: Mon, 9 Dec 2024 14:42:59 -0800 Subject: [PATCH] refactor: naming changes and general updates --- .../Dialog/Helper/MapExamplesViewModel.swift | 14 +++--- .../GoogleMaps_SwiftUIApp.swift | 7 +-- .../GoogleMaps-SwiftUI/Info.plist | 4 +- ...thDelegate.swift => HandleMapEvents.swift} | 2 +- .../GoogleMaps-SwiftUI/Samples/MapTypes.swift | 44 +++++++++++++++++++ ...tLevel.swift => MapWithCustomCamera.swift} | 2 +- .../Samples/MapWithTypes.swift | 40 ----------------- 7 files changed, 59 insertions(+), 54 deletions(-) rename GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/{MapWithDelegate.swift => HandleMapEvents.swift} (98%) create mode 100644 GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapTypes.swift rename GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/{MapWithStreetLevel.swift => MapWithCustomCamera.swift} (97%) delete mode 100644 GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithTypes.swift diff --git a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Dialog/Helper/MapExamplesViewModel.swift b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Dialog/Helper/MapExamplesViewModel.swift index 25b799e2..549c1960 100644 --- a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Dialog/Helper/MapExamplesViewModel.swift +++ b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Dialog/Helper/MapExamplesViewModel.swift @@ -23,9 +23,9 @@ class MapExamplesViewModel: ObservableObject { destination: AnyView(BasicMap()) ), MapExample( - title: "Map with Street Level", + title: "Map with custom camera", description: "Map camera position set to street-level 3D perspective.", - destination: AnyView(MapWithStreetLevel()) + destination: AnyView(MapWithCustomCamera()) ), MapExample( title: "Map with marker", @@ -38,19 +38,19 @@ class MapExamplesViewModel: ObservableObject { destination: AnyView(MapWithMarkers()) ), MapExample( - title: "Map with Types", + title: "Map types", description: "How to set the satellite, terrain, or hybrid map type property.", - destination: AnyView(MapWithTypes()) + destination: AnyView(MapTypes()) ), MapExample( - title: "Map with Containers", + title: "Map with containers", description: "Shows integration with SwiftUI layouts, allowing for standard modifiers like frame and padding.", destination: AnyView(MapWithContainer()) ), MapExample( - title: "Map with Delegates", + title: "Handle map events", description: "A GoogleMapView configured with handlers for map and marker tap events.", - destination: AnyView(MapWithDelegate()) + destination: AnyView(HandleMapEvents()) ) ] diff --git a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/GoogleMaps_SwiftUIApp.swift b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/GoogleMaps_SwiftUIApp.swift index 41806cae..c857781d 100644 --- a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/GoogleMaps_SwiftUIApp.swift +++ b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/GoogleMaps_SwiftUIApp.swift @@ -21,8 +21,9 @@ struct GoogleMaps_SwiftUIApp: App { /* API Key Setup: 1. Create a .xcconfig file at the project root level - 2. Add this line: API_KEY = your_api_key_here + 2. Add this line: MAPS_API_KEY = your_api_key_here 3. Get an API key from: https://developers.google.com/maps/documentation/ios-sdk/get-api-key + 4. Replace "your_api_key_here" with the API key obtained in step 3 Note: Never commit your actual API key to source control */ @@ -30,8 +31,8 @@ struct GoogleMaps_SwiftUIApp: App { guard let infoDictionary: [String: Any] = Bundle.main.infoDictionary else { fatalError("Info.plist not found") } - guard let apiKey: String = infoDictionary["API_KEY"] as? String else { - fatalError("API_KEY not set in Info.plist") + guard let apiKey: String = infoDictionary["MAPS_API_KEY"] as? String else { + fatalError("MAPS_API_KEY not set in Info.plist") } let _ = GMSServices.provideAPIKey(apiKey) diff --git a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Info.plist b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Info.plist index dd881182..b6770fae 100644 --- a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Info.plist +++ b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Info.plist @@ -2,7 +2,7 @@ - API_KEY - $(API_KEY) + MAPS_API_KEY + $(MAPS_API_KEY) diff --git a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithDelegate.swift b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/HandleMapEvents.swift similarity index 98% rename from GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithDelegate.swift rename to GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/HandleMapEvents.swift index 02a6f701..0fa3495b 100644 --- a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithDelegate.swift +++ b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/HandleMapEvents.swift @@ -14,7 +14,7 @@ import SwiftUI import GoogleMaps -struct MapWithDelegate: View { +struct HandleMapEvents: View { @State var response: String = "" diff --git a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapTypes.swift b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapTypes.swift new file mode 100644 index 00000000..55f272f0 --- /dev/null +++ b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapTypes.swift @@ -0,0 +1,44 @@ +// Copyright 2024 Google LLC. All rights reserved. +// +// +// 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. + +import SwiftUI +import GoogleMaps + +struct MapTypes: View { + // Initial options - set once at creation + private let mapOptions: GMSMapViewOptions = { + var options = GMSMapViewOptions() + options.camera = .camera(.googleplex) + return options + }() + + @State private var mapType: GMSMapViewType = .terrain + + var body: some View { + VStack { + GoogleMapView(options: mapOptions) + .mapType(mapType) + .ignoresSafeAreaExceptTop() + + // Available map types: + // .normal - Standard road map with streets, political boundaries, and labels + // .satellite - Satellite imagery without street labels or overlays + // .terrain - Topographic data showing elevation, vegetation, and natural features + // .hybrid - Satellite imagery combined with road overlays and place labels + Button("Switch to Satellite") { + mapType = .satellite + } + .padding() + } + } +} diff --git a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithStreetLevel.swift b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithCustomCamera.swift similarity index 97% rename from GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithStreetLevel.swift rename to GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithCustomCamera.swift index d468d1e2..3ed31934 100644 --- a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithStreetLevel.swift +++ b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithCustomCamera.swift @@ -14,7 +14,7 @@ import SwiftUI import GoogleMaps -struct MapWithStreetLevel: View { +struct MapWithCustomCamera: View { private var mapOptions: GMSMapViewOptions = { var options = GMSMapViewOptions() diff --git a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithTypes.swift b/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithTypes.swift deleted file mode 100644 index b25bc7d9..00000000 --- a/GoogleMaps-SwiftUI/GoogleMaps-SwiftUI/Samples/MapWithTypes.swift +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2024 Google LLC. All rights reserved. -// -// -// 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. - -import SwiftUI -import GoogleMaps - -struct MapWithTypes: View { - - private var mapOptions: GMSMapViewOptions = { - var options = GMSMapViewOptions() - // Initialize map centered on San Francisco - options.camera = .camera(.sanFrancisco) - - // Or with custom zoom level for closer view - // options.camera = .camera(.sanFrancisco, zoom: 15) - return options - }() - - var body: some View { - - // Available map types: - // .normal - Standard road map with streets, political boundaries, and labels - // .satellite - Satellite imagery without street labels or overlays - // .terrain - Topographic data showing elevation, vegetation, and natural features - // .hybrid - Satellite imagery combined with road overlays and place labels - GoogleMapView(options: mapOptions) - .mapType(.satellite) - .ignoresSafeAreaExceptTop() //optional property for samples display - } -}