UberCarAnimation is a delightful and interactive set of iOS projects demonstrating smooth and realistic car animations along routes. It includes examples for both UIKit and SwiftUI, using Google Maps and Apple MapKit.
- Realistic Animation: Lifelike animation of a car moving along a specified route, with smooth transitions.
- Customizable Appearance: (Primarily in UIKit Google Maps example) Developers can customize aspects like the car image, route color, and animation speed.
- Multiple Examples:
- UberCarAnimation (UIKit with Google Maps): The original example demonstrating car animation with Google Maps in a UIKit environment.
- SwiftUIExample/UberCarSwiftUI (SwiftUI with Google Maps): A SwiftUI wrapper around the Google Maps SDK, showcasing car animation.
- CarAnimationMapKitSwiftui (SwiftUI with Apple MapKit): A pure SwiftUI implementation using Apple's MapKit for car animation.
- Unit Tests: Each project includes unit tests for key components like ViewModels, Location Publishers, and Animators.
- Xcode: 15.3 or later (recommended)
- Swift: 5.9 or later (recommended)
- iOS:
- UIKit (Google Maps): iOS 13.0 or later (due to GoogleMaps SDK dependencies and modern practices)
- SwiftUI (Google Maps): iOS 14.0 or later (SwiftUI lifecycle and GoogleMaps wrapper)
- SwiftUI (MapKit): iOS 15.0 or later (for newer MapKit SwiftUI features if used, otherwise iOS 14)
- Google Maps API Key: Required for projects using Google Maps.
- CocoaPods: Required for dependency management in projects using Google Maps. Run
pod installin the respective project directories (UberCarAnimationandSwiftUIExample/UberCarSwiftUI).
- Clone the repository:
git clone https://github.com/SURYAKANTSHARMA/UberCarAnimation.git cd UberCarAnimation - Install Dependencies:
- For
UberCarAnimation(UIKit with Google Maps):cd UberCarAnimation pod install cd ..
- For
SwiftUIExample/UberCarSwiftUI(SwiftUI with Google Maps):cd SwiftUIExample/UberCarSwiftUI pod install cd ../..
- For
- API Key Setup:
- Obtain a Google Maps API Key:
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to "APIs & Services" > "Library" and enable the "Maps SDK for iOS".
- Go to "APIs & Services" > "Credentials" and create an API key.
- Create a file named
keys.swiftinside theUberCarAnimation/UberCarAnimation/directory (alongsideAppDelegate.swift). Note: Do not commit your real key to version control. The.gitignoreis set up to ignorekeys.swift. - Add your Google Maps API key to this file:
(Replace
// UberCarAnimation/UberCarAnimation/keys.swift import Foundation let googleMapsAPIKey = "YOUR_ACTUAL_GOOGLE_MAPS_API_KEY"
"YOUR_ACTUAL_GOOGLE_MAPS_API_KEY"with your real key.) - Add the
keys.swiftfile to your Xcode target so it gets compiled. TheAppDelegate.swiftis already refactored to usegoogleMapsAPIKeyfrom this file.
- Obtain a Google Maps API Key:
- Running: Open
UberCarAnimation.xcworkspacein Xcode and run theUberCarAnimationscheme. - Location Simulation: Once running in the simulator, select "Features" > "Location" > (e.g., "Freeway Drive") in the Simulator's menu bar to simulate movement.
- API Key Setup:
- Obtain a Google Maps API Key:
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to "APIs & Services" > "Library" and enable the "Maps SDK for iOS".
- Go to "APIs & Services" > "Credentials" and create an API key.
- Create a file named
keys.swiftinside theSwiftUIExample/UberCarSwiftUI/UberCarSwiftUI/directory (alongsideUberCarSwiftUIApp.swift). Note: Do not commit your real key to version control. The.gitignoreis set up to ignorekeys.swift. - Add your Google Maps API key to this file:
(Replace
// SwiftUIExample/UberCarSwiftUI/UberCarSwiftUI/keys.swift import Foundation let googleMapsAPIKey = "YOUR_ACTUAL_GOOGLE_MAPS_API_KEY"
"YOUR_ACTUAL_GOOGLE_MAPS_API_KEY"with your real key.) - Add the
keys.swiftfile to your Xcode target so it gets compiled. TheUberCarSwiftUIApp.swiftis already refactored to usegoogleMapsAPIKeyfrom this file during its initialization.
- Obtain a Google Maps API Key:
- Running: Open
SwiftUIExample/UberCarSwiftUI/UberCarSwiftUI.xcworkspacein Xcode and run theUberCarSwiftUIscheme. - Location Simulation: Similar to the UIKit example, use the Simulator's location features.
- API Key Setup: No API key is required for Apple MapKit.
- Running: Open
CarAnimationMapKitSwiftui/CarAnimationMapKitSwiftui.xcodeprojin Xcode and run theCarAnimationMapKitSwiftuischeme. - Location Simulation: Use the Simulator's location features. The app uses hardcoded coordinates for drawing a route for demonstration.
- Static Path: The Google Maps examples use a static encoded path string for drawing the route. For real-world applications, you would use the Google Directions API to get actual routes. See links in the original README below or Google's documentation.
- Map Style: Dark and Light mode map styles (
mapStyle1.json,mapStyle2.json) are included in theResourcesfolder of the respective Google Maps projects.
UberCarAnimation (UIKit - Google Maps):
| Light Mode | Dark Mode |
|---|---|
![]() |
![]() |
CarAnimationMapKitSwiftui (SwiftUI - Apple MapKit):
| Demo |
|---|
![]() |
- Pause and Play: For projects that include play/pause buttons:
- Simulate location updates in the simulator.
- Press the pause button to pause the car animation.
- Press the play button to resume the animation.
Each project within this repository now includes unit tests for its core components. To run these tests:
- Open the Project in Xcode:
- For
UberCarAnimation: OpenUberCarAnimation.xcworkspace. - For
CarAnimationMapKitSwiftui: OpenCarAnimationMapKitSwiftui/CarAnimationMapKitSwiftui.xcodeproj. - For
SwiftUIExample/UberCarSwiftUI: OpenSwiftUIExample/UberCarSwiftUI/UberCarSwiftUI.xcworkspace.
- For
- Select a Target Device: Choose a simulator (e.g., iPhone 15 Pro) or a connected physical device from the scheme selector at the top of the Xcode window.
- Run Tests:
- From the Xcode menu: Select "Product" > "Test".
- Keyboard Shortcut: Press Command-U (⌘U).
- View Test Results: The Test Navigator (Command-6, ⌘6) will show the progress and results of the tests.
For advanced users, tests can also be executed using the xcodebuild command-line tool. For example (from the directory containing the .xcworkspace or .xcodeproj):
# Example for a workspace
xcodebuild test -workspace YourProject.xcworkspace -scheme YourScheme -destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=latest'
# Example for a project
xcodebuild test -project YourProject.xcodeproj -scheme YourScheme -destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=latest'Replace YourProject.xcworkspace, YourProject.xcodeproj, and YourScheme with the actual names.
Contributions are welcome! If you encounter any issues or have ideas for improvements, please open an issue or submit a pull request on GitHub.
This collection of projects is available under the MIT license. See the LICENSE file for more information.
Follow SURYAKANTSHARMA on GitHub for the latest updates and releases.
A YouTube video by the original author demonstrates extracting code from the UIKit version for personal use. Note that the codebase has been significantly refactored since this video.


