Swift programming
iOS development
maps integration
open maps app
coordinates handling

How to open maps App programmatically with coordinates in swift?

Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms

Introduction

On iOS, the normal way to open the Maps app at a specific coordinate is to create an MKMapItem and call openInMaps. This approach is better than hand-building URL strings because it uses MapKit types directly and gives you cleaner control over labels, directions, and launch options.

Open a Coordinate in Apple Maps

The simplest case is to create a placemark from latitude and longitude, wrap it in an MKMapItem, and open it.

swift
1import MapKit
2
3func openLocation(latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
4    let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
5    let placemark = MKPlacemark(coordinate: coordinate)
6    let mapItem = MKMapItem(placemark: placemark)
7    mapItem.name = "Destination"
8    mapItem.openInMaps()
9}

This launches Apple Maps and shows that location. It is the standard answer when you simply want to display a pin.

Add Driving or Walking Directions

If the goal is navigation rather than just display, pass launch options.

swift
1import MapKit
2
3func openDirections(latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
4    let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
5    let placemark = MKPlacemark(coordinate: coordinate)
6    let destination = MKMapItem(placemark: placemark)
7    destination.name = "Office"
8
9    destination.openInMaps(launchOptions: [
10        MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving
11    ])
12}

You can switch the directions mode to walking or transit if that matches the app's behavior better.

Open Maps with a Region Hint

Sometimes you want Maps to open with a particular zoom context around the coordinate.

swift
1import MapKit
2
3func openLocationWithRegion(latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
4    let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
5    let span = MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)
6    let region = MKCoordinateRegion(center: coordinate, span: span)
7
8    let placemark = MKPlacemark(coordinate: coordinate)
9    let mapItem = MKMapItem(placemark: placemark)
10    mapItem.name = "Meeting Point"
11    mapItem.openInMaps(launchOptions: [
12        MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: region.center),
13        MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: region.span)
14    ])
15}

This is useful when the user should see some nearby context instead of a generic map view.

Use the Current Location with a Destination

If you want to open directions from the user's current position, use MKMapItem.forCurrentLocation() alongside the destination.

swift
1import MapKit
2
3func openRouteTo(latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
4    let destination = MKMapItem(placemark: MKPlacemark(
5        coordinate: CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
6    ))
7    destination.name = "Store"
8
9    MKMapItem.openMaps(
10        with: [MKMapItem.forCurrentLocation(), destination],
11        launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
12    )
13}

This is a better fit than opening only the destination when route guidance is the real goal.

Prefer MapKit Over URL Construction

You can also open Maps through URL schemes, but MKMapItem is usually the better default because it is type-safe and easier to maintain. URL construction is more fragile, especially when labels, route modes, or fallback behavior become more complex.

Use manual URLs only when you explicitly need integration with a different mapping app and have chosen that behavior intentionally.

Common Pitfalls

  • Building raw Maps URLs when MKMapItem already provides a cleaner API.
  • Forgetting to set a label or name, which makes the destination harder for users to recognize.
  • Opening the destination without directions when turn-by-turn navigation was the real intent.
  • Assuming region hints are mandatory when openInMaps() alone already solves the simple case.
  • Mixing location-acquisition concerns with map-opening logic in one function.

Summary

  • Use MKMapItem and openInMaps to open Apple Maps with coordinates.
  • Add launch options when you want directions or a specific map region.
  • Use MKMapItem.forCurrentLocation() when you want route guidance from the user's location.
  • Prefer MapKit APIs over raw URL construction for ordinary Apple Maps integration.
  • Keep the map-opening code focused on navigation intent rather than unrelated location logic.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms