> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/ios/ja/maps/llms.txt)

# Combine location

![Shows how to use Combine framework to drive the location puck.](https://docs.mapbox.com/ios/ja/assets/ideal-img/maps-examples-combine-location.c0b67bc.480.png)

This example demonstrates using the [Combine framework](https://developer.apple.com/documentation/combine/) to control the location and heading of the Puck on a map. It uses [Combine publishers](https://developer.apple.com/documentation/combine/publisher/) to update the Puck's `location` and `heading`. The map displays using the [`MapView`](https://docs.mapbox.com/ios/maps/api/latest/documentation/mapboxmaps/map-view/) class from the **Mapbox Maps SDK for iOS**, with custom location and heading providers set using Combine's [`eraseToSignal`](https://docs.mapbox.com/ios/maps/api/latest/documentation/mapboxmaps/signal/erasetosignal()/) method.

The Puck's appearance and behavior are configured through options like [`puckType`](https://docs.mapbox.com/ios/maps/api/latest/documentation/mapboxmaps/pucktype/), [`puckBearing`](https://docs.mapbox.com/ios/maps/api/latest/documentation/mapboxmaps/puckbearing/), and [`puckBearingEnabled`](https://docs.mapbox.com/ios/maps/api/latest/documentation/mapboxmaps/locationoptions/puckbearingenabled/). Additionally, the viewport is configured to continuously follow the Puck's location, enabling seamless tracking. Users can interact with the map by tapping on it, which changes the Puck's position based on the tap location, calculating and setting the heading.

> **Note: iOS Examples App Available**
> 
> This example code is part of the **Maps SDK for iOS Examples App**, a working iOS project [available on Github](https://github.com/mapbox/mapbox-maps-ios/tree/11.29.0/Sources/Examples). iOS developers are encouraged to run the examples app locally to interact with this example in an emulator and explore other features of the Maps SDK.
> 
> See our [Run the Maps SDK for iOS Examples App](https://docs.mapbox.com/help/tutorials/maps-sdk-ios-examples-app/) tutorial for step-by-step instructions.

**Swift**

Title: `CombineLocationExample.swift`

[View on GitHub](https://github.com/mapbox/mapbox-maps-ios/blob/main/Sources/Examples/All%20Examples/Lab/CombineLocationExample.swift)

```swift
import UIKit
import MapboxMaps
import Combine
import Turf

/// This examples shows how to use Combine framework to drive the Puck's location and heading.
final class ViewController: UIViewController {
    @Published
    private var location = Location(coordinate: CLLocationCoordinate2D(latitude: 60.17195694011002, longitude: 24.945389069265598))
    @Published
    private var heading = Heading(direction: 0, accuracy: 0)

    private var mapView: MapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        mapView = MapView(frame: view.bounds)
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        view.addSubview(mapView)

        // Set the custom location & heading providers
        mapView.location.override(
            locationProvider: $location.map { [$0] }.eraseToSignal(),
            headingProvider: $heading.eraseToSignal())

        // Enable the location puck
        mapView.location.options = LocationOptions(
            puckType: .puck2D(.makeDefault(showBearing: true)),
            puckBearing: .heading,
            puckBearingEnabled: true
        )

        // Set up the follow-puck viewport, so camera will always be focused on the puck
        mapView.viewport.transition(
            to: mapView.viewport.makeFollowPuckViewportState(options: .init(zoom: 16, bearing: .constant(0), pitch: 0)),
            transition: mapView.viewport.makeImmediateViewportTransition())

        mapView.gestures.singleTapGestureRecognizer.addTarget(self, action: #selector(onTap))

        let guideLabel = UILabel()
        guideLabel.text = "Tap anywhere on the map to place the puck"
        guideLabel.backgroundColor = .systemBackground
        guideLabel.translatesAutoresizingMaskIntoConstraints = false

        view.addSubview(guideLabel)
        NSLayoutConstraint.activate([
            guideLabel.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -30),
            guideLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor)
        ])
    }

    @objc func onTap(_ gesture: UIGestureRecognizer) {
        // Place the puck to the tap location
        let point = gesture.location(in: mapView)
        let coordinate = mapView.mapboxMap.coordinate(for: point)

        // Calculating the angle between the current coordinate, and the target coordinate
        let headingDirection = location.coordinate.direction(to: coordinate)

        location = Location(coordinate: coordinate)
        heading = Heading(direction: headingDirection, accuracy: 0)
    }

    
}
```