Skip to content

Commit 43bd9f6

Browse files
feat: Replace Google-map based implementation with Places API [Phase 2] (#25)
1 parent 00c846a commit 43bd9f6

4 files changed

Lines changed: 86 additions & 92 deletions

File tree

GooglePlacesDemos/GooglePlacesDemos/GooglePlacesDemosApp.swift

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
// permissions and limitations under the License.
1313

1414
import GooglePlacesSwift
15-
import GoogleMaps
1615
import SwiftUI
1716

1817
@main
1918
struct GooglePlacesDemosApp: App {
2019
init() {
2120
setupGooglePlaces()
22-
setupGoogleMaps()
2321
}
2422

2523
var body: some Scene {
@@ -46,23 +44,9 @@ struct GooglePlacesDemosApp: App {
4644
}
4745

4846
let _ = PlacesClient.provideAPIKey(apiKey)
49-
GMSServices.addInternalUsageAttributionID("gmp_git_iosplacessamples_v1.0.0")
47+
PlacesClient.addInternalUsageAttributionID("gmp_git_iosplacessamples_v1.0.0")
5048
#if DEBUG
5149
print("Places SDK Licenses:\n\(PlacesClient.openSourceLicenseInfo)")
5250
#endif
5351
}
54-
55-
private func setupGoogleMaps() {
56-
// Skip API key requirement in test environments
57-
if isTestEnvironment {
58-
let _ = GMSServices.provideAPIKey("TEST_DUMMY_KEY")
59-
return
60-
}
61-
62-
guard let mapKey = Bundle.main.infoDictionary?["MAPS_API_KEY"] as? String, !mapKey.isEmpty else {
63-
fatalError("Add your MAPS_API_KEY to Info.plist - Get one at https://developers.google.com/maps/documentation/ios-sdk/get-api-key")
64-
}
65-
66-
let _ = GMSServices.provideAPIKey(mapKey)
67-
}
6852
}

GooglePlacesDemos/GooglePlacesDemos/Samples/AutocompleteBasic.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import SwiftUI
1515
import GooglePlacesSwift
16-
import GoogleMaps
1716

1817
struct AutocompleteBasic: View {
1918

@@ -27,20 +26,6 @@ struct AutocompleteBasic: View {
2726
@State private var state = ""
2827
@State private var zipCode = ""
2928
@State private var display_address = ""
30-
31-
private let mapOptions: GMSMapViewOptions = {
32-
var options = GMSMapViewOptions()
33-
options.camera = GMSCameraPosition(
34-
latitude: 37.4220, // Googleplex coordinates
35-
longitude: -122.0841,
36-
zoom: 11
37-
)
38-
return options
39-
}()
40-
41-
// Map camera and markers
42-
@State private var newCamera: GMSCameraPosition?
43-
@State private var currentMarkers: [GMSMarker] = []
4429

4530
var body: some View {
4631
Form {
@@ -79,18 +64,6 @@ struct AutocompleteBasic: View {
7964
TextField("Zipcode", text: $zipCode)
8065
}
8166
}
82-
83-
//map object
84-
Section {
85-
GoogleMapView(options: mapOptions)
86-
.camera(newCamera)
87-
.mapMarkers(currentMarkers)
88-
.frame(maxWidth: .infinity, minHeight: 325)
89-
.listRowInsets(EdgeInsets())
90-
} footer: {
91-
Text("The map updates to show selected place location.")
92-
}
93-
9467
}
9568
}
9669

@@ -121,7 +94,6 @@ struct AutocompleteBasic: View {
12194
self.state = ""
12295
self.zipCode = ""
12396
self.display_address = ""
124-
self.currentMarkers = []
12597
}
12698

12799
// Function to fetch and process address details
@@ -134,17 +106,6 @@ struct AutocompleteBasic: View {
134106
if let components = place.addressComponents {
135107
processAddressComponents(components)
136108
}
137-
138-
// Update map camera with place location
139-
newCamera = GMSCameraPosition(
140-
target: place.location,
141-
zoom: 17
142-
)
143-
144-
// Create new marker at place location
145-
let marker = GMSMarker(position: place.location)
146-
marker.title = place.displayName
147-
currentMarkers = [marker] // Replace existing markers with new one
148109
}
149110
}
150111

GooglePlacesDemos/GooglePlacesDemos/Samples/PlaceCardView.swift

Lines changed: 84 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,100 @@
1212
// permissions and limitations under the License.
1313

1414
import SwiftUI
15-
import GoogleMaps
15+
import GooglePlacesSwift
1616

1717
struct PlaceCardView: View {
1818
let placeId: String
1919
@StateObject private var placeDetailsManager = PlaceDetailsManager()
20-
@State private var cameraPosition: GMSCameraPosition?
21-
20+
2221
var body: some View {
23-
VStack(spacing: 16) {
24-
if let place = placeDetailsManager.place {
25-
26-
// Map View in top portion
27-
GoogleMapView(options: GMSMapViewOptions())
28-
.camera(cameraPosition)
29-
.ignoresSafeArea(.container, edges: [.bottom, .horizontal])
30-
.frame(maxWidth: .infinity, minHeight: 325)
31-
32-
// Place Details Card in bottom portion
33-
PlaceDetailsCard(place: place, isOpen: placeDetailsManager.isOpen)
34-
.frame(maxWidth: .infinity, alignment: .leading)
35-
36-
//provide place summary
37-
if let summary = place.editorialSummary {
38-
Text(summary)
39-
.font(.subheadline)
40-
.foregroundColor(.secondary)
41-
.padding(.horizontal)
42-
.padding(.bottom)
22+
GeometryReader { geometry in
23+
VStack(spacing: 0) {
24+
if let place = placeDetailsManager.place {
25+
26+
// Place photo or location display - 45% of screen
27+
Group {
28+
if !placeDetailsManager.loadedPhotos.isEmpty {
29+
// Show first photo if available
30+
Image(uiImage: placeDetailsManager.loadedPhotos[0])
31+
.resizable()
32+
.scaledToFill()
33+
.frame(width: geometry.size.width, height: geometry.size.height * 0.45)
34+
.clipped()
35+
} else if placeDetailsManager.photos != nil && !placeDetailsManager.photos!.isEmpty {
36+
// Loading photo
37+
ProgressView("Loading photo...")
38+
.frame(width: geometry.size.width, height: geometry.size.height * 0.45)
39+
.background(Color(.systemGroupedBackground))
40+
} else {
41+
// No photos available - show location info
42+
VStack(spacing: 12) {
43+
Image(systemName: "photo.on.rectangle.angled")
44+
.font(.system(size: 60))
45+
.foregroundColor(.gray.opacity(0.5))
46+
47+
Text("No photos available")
48+
.font(.headline)
49+
.foregroundColor(.secondary)
50+
51+
Text("Lat: \(String(format: "%.4f", place.location.latitude)), Lon: \(String(format: "%.4f", place.location.longitude))")
52+
.font(.caption)
53+
.foregroundColor(.secondary)
54+
}
55+
.frame(width: geometry.size.width, height: geometry.size.height * 0.45)
56+
.background(Color(.systemGroupedBackground))
57+
}
58+
}
59+
60+
// Content below photo
61+
VStack(alignment: .leading, spacing: 12) {
62+
// Place Details Card
63+
PlaceDetailsCard(place: place, isOpen: placeDetailsManager.isOpen)
64+
.padding(.horizontal)
65+
.padding(.top, 16)
66+
67+
//provide place summary
68+
if let summary = place.editorialSummary {
69+
Text(summary)
70+
.font(.subheadline)
71+
.foregroundColor(.secondary)
72+
.padding(.horizontal)
73+
}
74+
75+
Spacer()
76+
}
77+
.frame(maxHeight: .infinity)
78+
79+
} else {
80+
ProgressView()
81+
.frame(maxWidth: .infinity, maxHeight: .infinity)
4382
}
44-
} else {
45-
ProgressView()
4683
}
4784
}
85+
.ignoresSafeArea(edges: .top)
4886
.task {
49-
await placeDetailsManager.fetchPlaceDetails(placeID: placeId)
50-
51-
if let place = placeDetailsManager.place {
52-
cameraPosition = GMSCameraPosition(
53-
latitude: place.location.latitude,
54-
longitude: place.location.longitude,
55-
zoom: 15
56-
)
57-
}
58-
87+
// Fetch place details with photos included
88+
let propertiesWithPhotos: [PlaceProperty] = [
89+
.businessStatus,
90+
.displayName,
91+
.placeID,
92+
.priceLevel,
93+
.rating,
94+
.numberOfUserRatings,
95+
.types,
96+
.currentOpeningHours,
97+
.supportsDineIn,
98+
.supportsTakeout,
99+
.supportsDelivery,
100+
.supportsCurbsidePickup,
101+
.coordinate,
102+
.editorialSummary,
103+
.photos
104+
]
105+
await placeDetailsManager.fetchPlaceDetails(placeID: placeId, properties: propertiesWithPhotos)
59106
await placeDetailsManager.checkIfOpen(placeID: placeId)
107+
// Fetch actual photo images
108+
await placeDetailsManager.fetchPhotosForPlace(placeID: placeId, maxPhotos: 1)
60109
}
61110
}
62111
}

GooglePlacesDemos/GooglePlacesDemos/Samples/TextSearchView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// permissions and limitations under the License.
1313

1414
import GooglePlacesSwift
15-
import GoogleMaps
15+
import CoreLocation
1616
import SwiftUI
1717

1818
struct TextSearchView: View {

0 commit comments

Comments
 (0)