Interact with third-party iOS map clients, using custom URL schemes or helper methods allowing your user to pick their preferred map client.
Client | URL Scheme | App Store |
---|---|---|
Apple Maps | maps |
link |
Google Maps | comgooglemaps |
link |
Waze | waze |
link |
More to come... |
Unfortunately, not all map clients offer URL schemes to be supported by ThirdPartyMapper
. If you’re aware of another candidate, please let us know.
In Xcode, click on the “File” menu, “Swift Packages”, “Add Package Dependency…”, then enter the URL for this repo:
https://github.com/lordzsolt/ThirdPartyMapper.git
With CocoaPods, simply add ThirdPartyMapper to your Podfile:
pod 'ThirdPartyMapper'
Or, you can manually import the files from the Sources folder.
In order for ThirdPartyMapper to work, you need to declare URL Schemes of the Apps you would like to use in the Info.plist
file of your project:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
<string>waze</string>
</array>
You will notice that most methods have a parameter isExactLocation
. This is to specify if the searchQuery
should be used to navigate the user to an exact location, such as an address.
In case you want to highlight a general area on a map, such as California, pass false
to this argument. This feature is not supported by all apps.
let clients = ThirdPartyMapper.allowedClients
Sometimes depending on which geogrephical region you are making your app available, you could decide to show the list of clients in a different order, or show a specific list of your choice. This is why ThirdPartyMapper.allowedClients
is publically settable.
ThirdPartyMapper.allowedClients = [.waze, .googleMaps]
let installedClients = ThirdPartyMapper.installedClients(
searchQuery: "One Apple Park Way, Cupertino, CA 95014, United States",
isExactLocation: true)
ThirdPartyMapper.openClientPicker(
searchQuery: "One Apple Park Way, Cupertino, CA 95014, United States",
isExactLocation: true,
on: viewController)
struct ContentView: View {
private static let appleCampusAddress = "One Apple Park Way, Cupertino, CA 95014, United States"
@State var isMapPickerShown = false
var body: some View {
VStack {
Button("Apple Campus") {
isMapPickerShown = true
}
.buttonStyle(.bordered)
.frame(height: 40)
}
.mapPicker(
searchQuery: Self.appleCampusAddress,
isExactLocation: true,
isPresented: $isConfirmationDialogShown)
}
}
struct ContentView: View {
private static let appleCampusAddress = "One Apple Park Way, Cupertino, CA 95014, United States"
@State var isMapPickerShown = false
var body: some View {
VStack {
Button("Apple Campus") {
isMapPickerShown = true
}
.buttonStyle(.bordered)
.frame(height: 40)
}
.mapPickerActionSheet(
searchQuery: Self.appleCampusAddress,
isExactLocation: true,
isPresented: $isConfirmationDialogShown)
}
}
ThirdPartyMapper is written in Swift 5.0, requires iOS 11.0 and above, Xcode 10.2 and above.
ThirdPartyMapper was created by Zsolt Kovacs.
The project takes inspiration from ThirdPartyMailer.
ThirdPartyMapper is available under the MIT license. See the LICENSE file for more info.