Google Maps Setup
This section covers the setup process for Google Maps SDK integration with MapConductor.
Use this provider when your app already depends on Google Maps SDK for iOS or needs Google map types through GoogleMapDesign.
Prerequisites
Section titled “Prerequisites”- iOS development environment (Xcode 15+)
- Google Cloud Console account
- Maps SDK for iOS enabled in your Google Cloud project
- iOS deployment target set to 16.0 or higher
Setup Steps
Section titled “Setup Steps”1. Google Cloud Console Configuration
Section titled “1. Google Cloud Console Configuration”- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Maps SDK for iOS API
- Go to Credentials and create an API key
- Restrict the API key to your app’s bundle ID
2. Swift Package Manager Configuration
Section titled “2. Swift Package Manager Configuration”Add the Google Maps SDK and MapConductor to your Xcode project:
- In Xcode, go to File > Add Packages
- Add the package:
https://github.com/MapConductor/ios-for-googlemaps
3. Initialize Google Maps in Your App
Section titled “3. Initialize Google Maps in Your App”Call GMSServices.provideAPIKey(_:) once before any map view is displayed. The recommended
place is your @main App struct:
import SwiftUIimport GoogleMapsimport MapConductorForGoogleMaps
@mainstruct MyApp: App { init() { GMSServices.provideAPIKey("YOUR_GOOGLE_MAPS_API_KEY") }
var body: some Scene { WindowGroup { ContentView() } }}Alternatively, pass the call via the sdkInitialize parameter on GoogleMapView:
GoogleMapView( state: mapState, sdkInitialize: { GMSServices.provideAPIKey("YOUR_GOOGLE_MAPS_API_KEY") }) { ... }4. Add Location Permissions (if needed)
Section titled “4. Add Location Permissions (if needed)”If your app uses location services with Google Maps, add to Info.plist:
<key>NSLocationWhenInUseUsageDescription</key><string>We need your location to display on the map</string>Verification
Section titled “Verification”Build and run your app with the following code to verify the setup:
import SwiftUIimport MapConductorCoreimport MapConductorForGoogleMaps
struct ContentView: View { @StateObject var mapState = GoogleMapViewState( cameraPosition: MapCameraPosition( position: GeoPoint(latitude: 37.7749, longitude: -122.4194), zoom: 12.0 ) )
var body: some View { GoogleMapView(state: mapState) .ignoresSafeArea() }}If the map displays without errors, your setup is working. Test basic interactions (zoom, pan) to confirm everything is functioning correctly.
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Map not displaying (gray screen)
- Verify
GMSServices.provideAPIKey(_:)is called before any map view is created - Check that Maps SDK for iOS is enabled in Google Cloud Console
- Ensure the API key is not restricted to a different bundle ID
- Verify iOS deployment target is 16.0 or higher
API key errors
- Double-check the API key value passed to
GMSServices.provideAPIKey(_:) - Verify the key has not been revoked
- Check that Maps SDK for iOS is enabled in Google Cloud Console
- Verify bundle ID restriction matches your app’s actual bundle ID
Build errors with CocoaPods conflicts
- Ensure you’re using Swift Package Manager only (not mixing with CocoaPods)
- Clean build folder (Cmd+Shift+K)
- Delete derived data:
~/Library/Developer/Xcode/DerivedData - Rebuild project
Location Services
Section titled “Location Services”If you need location-based features:
- Add location permissions to Info.plist (see step 4)
- Request user permission in your app:
import CoreLocation
class LocationManager: NSObject, CLLocationManagerDelegate { let manager = CLLocationManager()
override init() { super.init() manager.delegate = self manager.requestWhenInUseAuthorization() }}Next Steps
Section titled “Next Steps”Once Google Maps SDK is properly configured, you can use MapConductor’s GoogleMapView component as described in the Map View component documentation.
For more examples, see the Get Started tutorial.