Skip to content

Instantly share code, notes, and snippets.

View rockarts's full-sized avatar
💭
🐝 🇨🇦

Steven Rockarts rockarts

💭
🐝 🇨🇦
  • Edmonton, AB
View GitHub Profile
@rockarts
rockarts / ViewController.swift
Created September 3, 2018 04:09
Navigate using Mapbox
import UIKit
import Mapbox
import MapboxNavigation
import MapboxCoreNavigation
import MapboxDirections
class ViewController: UIViewController {
var mapView: MGLMapView!
@objc @IBAction func handleMapTap(sender: UITapGestureRecognizer) {
let point = sender.location(in: sender.view!)
let coordinate = mapView.convert(point, toCoordinateFrom: mapView)
points.append(coordinate)
let annotation = MGLPointAnnotation()
annotation.coordinate = coordinate
mapView.addAnnotation(annotation)
//ADD THESE 2 LINES TO ENABLE THE NAVIGATION BUTTON
if (points.count) > 1 {
// Begin navigation when navigation button is tapped
@objc func startNavigation(sender: UIButton) {
let options = NavigationRouteOptions(coordinates: points)
options.profileIdentifier = .automobile
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first, error == nil else {
print(error!.localizedDescription)
return
// Setup navigation button
button = UIButton(frame: CGRect(x: 20, y: 50, width: self.mapView.frame.width - 40, height: 45))
button.setTitle("Tap to add points", for: .disabled)
button.setTitle("Start navigation", for: .normal)
button.backgroundColor = UIColor(red:0.77, green:0.77, blue:0.77, alpha:1.0)
button.addTarget(self, action: #selector(startNavigation(sender:)), for: .touchUpInside)
button.isEnabled = false
mapView.addSubview(button)
// Handle single taps
@objc @IBAction func handleMapTap(sender: UITapGestureRecognizer) {
let point = sender.location(in: sender.view!)
let coordinate = mapView.convert(point, toCoordinateFrom: mapView)
points.append(coordinate)
let annotation = MGLPointAnnotation()
annotation.coordinate = coordinate
mapView.addAnnotation(annotation)
}
// Setup single tap gesture
let singleTap = UITapGestureRecognizer(target: self, action: #selector(handleMapTap(sender:)))
for recognizer in mapView.gestureRecognizers! where recognizer is UITapGestureRecognizer {
singleTap.require(toFail: recognizer)
}
mapView.addGestureRecognizer(singleTap)
@rockarts
rockarts / ViewController.swift
Last active September 3, 2018 02:02
Add Gesture Recognizer
//
// ViewController.swift
// ExploreOutdoors
//
// Created by Steven Rockarts on 2018-09-01.
// Copyright © 2018 Figure4Software. All rights reserved.
//
import UIKit
import Mapbox
source 'https://github.com/CocoaPods/Specs.git'
project 'ExploreOutdoors.xcodeproj'
platform :ios, '11'
workspace 'ExploreOutdoors'
use_frameworks!
target 'ExploreOutdoors' do
pod 'Mapbox-iOS-SDK'
import UIKit
import Mapbox
import MapboxNavigation
import MapboxCoreNavigation
import MapboxDirections
class ViewController: UIViewController {
var mapView: MGLMapView!
@rockarts
rockarts / JasperRockClimbs.geojson
Created September 2, 2018 16:32
A GeoJson file of all the rock climbs in Jasper National Park
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.