|
12 | 12 | // permissions and limitations under the License. |
13 | 13 |
|
14 | 14 | import SwiftUI |
15 | | -import GoogleMaps |
| 15 | +import GooglePlacesSwift |
16 | 16 |
|
17 | 17 | struct PlaceCardView: View { |
18 | 18 | let placeId: String |
19 | 19 | @StateObject private var placeDetailsManager = PlaceDetailsManager() |
20 | | - @State private var cameraPosition: GMSCameraPosition? |
21 | | - |
| 20 | + |
22 | 21 | 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) |
43 | 82 | } |
44 | | - } else { |
45 | | - ProgressView() |
46 | 83 | } |
47 | 84 | } |
| 85 | + .ignoresSafeArea(edges: .top) |
48 | 86 | .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) |
59 | 106 | await placeDetailsManager.checkIfOpen(placeID: placeId) |
| 107 | + // Fetch actual photo images |
| 108 | + await placeDetailsManager.fetchPhotosForPlace(placeID: placeId, maxPhotos: 1) |
60 | 109 | } |
61 | 110 | } |
62 | 111 | } |
0 commit comments