• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Custom Location View Style

This example shows how to customize the location view style for NGLMapView.

  • Move the map camera to the given location after the map is loaded

  • Update the map location mode by use setUserTrackingMode method

docs-image

For all code examples, refer to Maps Code Examples

LocationStyleViewController view source

1import UIKit
2import Nbmap
3enum LocationType {
4 case HidePuckView
5 case UpdateToFollow
6 case UpdateToFollowWithHeading
7 case UpdateToFollowWithCourse
8 case GetUserLocation
9}
10class LocationStyleViewController: UIViewController {
11 var nbMapView: NGLMapView! {
12 didSet {
13 oldValue?.removeFromSuperview()
14 if let mapView = nbMapView {
15 view.insertSubview(mapView, at: 0)
16 }
17 }
18 }

The example code is a LocationStyleViewController class that sets up a map view (NGLMapView) and handles various location-related functionalities.

Initializing MapView:

  • The nbMapView property is initialized as an instance of NGLMapView and added as a subview to the view controller's view.

  • The autoresizingMask property is set to allow the map view to resize with the view controller's view.

  • The delegate property is set to self to receive map view delegate callbacks.

Custom User Location Style:

  • The mapView(styleForDefaultUserLocationAnnotationView:) method is implemented to customize the appearance of the default user location annotation view.

  • A NGLUserLocationAnnotationViewStyle object is created and configured with various properties to customize the puck, arrow, and halo colors. The method returns the configured NGLUserLocationAnnotationViewStyle object.

Setting User Tracking Mode:

  • Depending on the selected LocationType, the method calls nbMapView.setUserTrackingMode with the appropriate mode.

  • The setUserTrackingMode(_:animated:completionHandler:) method is used to set the user tracking mode for the map view.

    • NGLUserTrackingModeNone The map does not follow the user location.

    • NGLUserTrackingModeFollow The map follows the user location. This tracking mode falls back to NGLUserTrackingModeNone if the user pans the map view.

    • NGLUserTrackingModeFollowWithHeading The map follows the user location and rotates when the heading changes.

    • NGLUserTrackingModeFollowWithCourse The map follows the user location and rotates when the course changes.

Have Questions ?