Skip to content

Instantly share code, notes, and snippets.

@mzeeshanid
Created February 12, 2020 05:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzeeshanid/6d79c3e69bd778be96e1851549455a47 to your computer and use it in GitHub Desktop.
Save mzeeshanid/6d79c3e69bd778be96e1851549455a47 to your computer and use it in GitHub Desktop.
Directed GMSPolyline
//
// DirectedPolylineViewController.swift
//
//
// Created by Mac OS X on 11/02/2020.
// Copyright © 2020 Muhammad Zeeshan. All rights reserved.
//
import UIKit
import GoogleMaps
import CoreLocation
class DirectedPolylineViewController: UIViewController {
@IBOutlet var mapView: GMSMapView!
var geoJson: [[CLLocationDegrees]] = [
[-118.2608582418, 34.0801788388],
[-118.2605869562, 34.0800219712],
[-118.2601800293, 34.0797865312],
[-118.2596010753, 34.0794525362],
[-118.2586218209, 34.078885827],
[-118.2576888882, 34.0783437419],
[-118.2567295072, 34.0777879666],
[-118.2568708641, 34.0775788277],
[-118.256982542, 34.0773834912],
[-118.2570810611, 34.0772046699],
[-118.2573405786, 34.0767617098],
[-118.2577793783, 34.0769528505],
[-118.2577793783, 34.0769528505],
[-118.2583954205, 34.0772211006],
[-118.2593609846, 34.0776394559],
[-118.2597743412, 34.0778226751],
[-118.2599132506, 34.0778910731],
[-118.2600752764, 34.0779594212],
[-118.2601975893, 34.0780003759],
[-118.2602637036, 34.0780222165],
[-118.2603430185, 34.0780412807],
[-118.2604817748, 34.0780602167],
[-118.2605247217, 34.0780656198],
[-118.2605709538, 34.0780655201],
[-118.2606204883, 34.0780654132],
[-118.2608846376, 34.0780538515],
[-118.261514738, 34.0779541152],
[-118.261514738, 34.0779541152],
[-118.2616768014, 34.0779284838],
[-118.263116814, 34.0776785969],
[-118.263116814, 34.0776785969],
[-118.2634722773, 34.0776168193],
[-118.2640993802, 34.0775110307],
[-118.2643601469, 34.077474738],
[-118.2645383739, 34.0774441212],
[-118.264766161, 34.0774216391],
[-118.2649510793, 34.0774184858],
[-118.2651162189, 34.0774263671],
[-118.2652318419, 34.0774398527],
[-118.2653078551, 34.0774589208],
[-118.2654169434, 34.0774944036],
[-118.2655359648, 34.077538108],
[-118.2656252571, 34.0775791297],
[-118.2657211976, 34.0776338762],
[-118.2657840806, 34.0776777038],
[-118.2658999749, 34.0777763722],
[-118.2659795268, 34.0778696248],
[-118.2660358579, 34.0779299539],
[-118.2662136605, 34.078077123],
[-118.2662136605, 34.078077123],
[-118.2662709416, 34.078124535],
[-118.2663470694, 34.0781793246],
[-118.2664661885, 34.0782532545],
[-118.2667308108, 34.0783900642],
[-118.2686425274, 34.0793146091],
[-118.2688330869, 34.0794213522],
[-118.2688330869, 34.0794213522],
[-118.2689700515, 34.0794979878],
[-118.269492726, 34.079777106],
[-118.2696449713, 34.0798811855],
[-118.2697475928, 34.0799578969],
[-118.2698767044, 34.0800565319],
[-118.2700058429, 34.0801634104],
[-118.2702520121, 34.0804112678],
[-118.2702520121, 34.0804112678],
[-118.2703570406, 34.0805171007],
[-118.2705492282, 34.0807172652],
[-118.2708044471, 34.0810052201],
[-118.2709071689, 34.0811121569],
[-118.2710595431, 34.0812547045],
[-118.271231759, 34.0814054511],
[-118.2714767986, 34.0816082433],
[-118.271635717, 34.0817315404],
[-118.2720362416, 34.0820164181],
[-118.2726585803, 34.0824684143],
[-118.2728207597, 34.0825779631],
[-118.2729697118, 34.0826820458],
[-118.2731881419, 34.0828244415],
[-118.2733139954, 34.0829340718],
[-118.273430928, 34.0830423483],
[-118.273430928, 34.0830423483],
[-118.273535936, 34.0831396601],
[-118.2737480781, 34.0833782446],
[-118.2738972937, 34.083562014],
[-118.273957009, 34.0836443148],
[-118.2741530553, 34.0840093374],
[-118.2742595021, 34.0842426651],
[-118.2745089061, 34.0847641948],
[-118.2747513543, 34.0852785954],
[-118.2747513543, 34.0852785954],
[-118.2748115517, 34.0854065094],
[-118.2758158555, 34.0875035972],
[-118.275938567, 34.0877588693],
[-118.275938567, 34.0877588693],
[-118.2763080364, 34.0885274299],
[-118.2763712237, 34.0886591834],
[-118.2768235214, 34.089603417],
[-118.2768248516, 34.0896061618],
[-118.2768248516, 34.0896061618],
[-118.2768700511, 34.0896912424],
[-118.2768966004, 34.0897296518],
[-118.2769132234, 34.0897625882],
[-118.2769828998, 34.0898586041],
[-118.2772248757, 34.0901218451],
[-118.2773110211, 34.0902040837],
[-118.2774401847, 34.0903109543],
[-118.2776024039, 34.0904259924],
[-118.2777248258, 34.0904916601],
[-118.2778869179, 34.0905682279],
[-118.2783697194, 34.0907457283],
[-118.2784755552, 34.0907894504],
[-118.2786145015, 34.090857827],
[-118.2786356788, 34.090869594],
[-118.2786356788, 34.090869594],
[-118.2787733289, 34.0909453926],
[-118.2789354595, 34.0910329504],
[-118.2790413602, 34.091095907],
[-118.2792069501, 34.0912301704],
[-118.2792864562, 34.0913014314],
[-118.2794422211, 34.091460448],
[-118.2795019474, 34.0915427461],
[-118.2796345383, 34.0916853288],
[-118.2798897208, 34.0919430383],
[-118.2799636161, 34.0920151362],
[-118.2799636161, 34.0920151362],
[-118.2803967139, 34.0924364803],
[-118.2805027557, 34.0925406535],
[-118.2811058537, 34.0931272972],
[-118.2811853818, 34.0932040527],
[-118.281821463, 34.0937741289],
[-118.2826861373, 34.0945453613],
[-118.2826861373, 34.0945453613],
[-118.2827987775, 34.0946456699],
[-118.2831499413, 34.0949553575],
[-118.2840843258, 34.0958214931],
[-118.2843158731, 34.0960174216],
[-118.2843158731, 34.0960174216],
[-118.284988656, 34.096586021],
[-118.285266963, 34.096835421],
[-118.2857837107, 34.0972656165],
[-118.2861115119, 34.0974984103],
[-118.2862274294, 34.0975888156],
[-118.286518824, 34.0977997115],
[-118.2866711233, 34.0979037696],
[-118.2870054319, 34.0981063188],
[-118.2871246165, 34.0981857241],
[-118.2873458667, 34.0981687109],
[-118.2874053222, 34.0981685695],
[-118.287659641, 34.0981624685],
[-118.2877356139, 34.0981628372],
[-118.2877356139, 34.0981628372],
[-118.2884986438, 34.0981659639],
[-118.2895424191, 34.0981634672],
[-118.2914912397, 34.0981587814],
[-118.2914912397, 34.0981587814],
[-118.2916002416, 34.0981585184],
[-118.2917587897, 34.0981581357],
[-118.2928818291, 34.0981526708],
[-118.2939487257, 34.0981500799],
[-118.2950453499, 34.0981474071],
[-118.296132055, 34.0981420007],
[-118.2964623635, 34.0981411907],
[-118.2964623635, 34.0981411907],
[-118.2972154668, 34.0981393405],
[-118.2981535339, 34.0981345563],
[-118.2981535339, 34.0981345563],
[-118.2983186871, 34.0981338739],
[-118.2994252202, 34.0981311368],
[-118.3003467806, 34.0981288495],
[-118.3003467806, 34.0981288495],
[-118.3005119348, 34.0981284389],
[-118.3021535673, 34.0981243448],
[-118.3031445022, 34.0981246106],
[-118.3032336854, 34.0981243868],
[-118.3033988396, 34.0981239722],
[-118.3033988396, 34.0981239722],
[-118.3043534306, 34.0981215714],
[-118.3056152082, 34.0981183865],
[-118.3070553522, 34.0981147353],
[-118.3092353865, 34.0981091755],
[-118.3095656947, 34.0981083297],
[-118.3095656947, 34.0981083297],
[-118.3109397767, 34.0981048014],
[-118.3114187236, 34.0981035679],
[-118.3134302908, 34.0980958935],
[-118.3134302908, 34.0980958935],
[-118.3135954438, 34.0980951901],
[-118.3139719951, 34.0980942122],
[-118.3141206234, 34.0980910781],
[-118.3142527363, 34.0980879866],
[-118.3143716472, 34.0980876773],
[-118.3146061452, 34.0980815712],
[-118.3147679962, 34.0980811497],
[-118.3149166141, 34.0980752667],
[-118.3157621922, 34.0980703119],
[-118.3178100723, 34.0980572487],
[-118.3178100723, 34.0980572487],
[-118.3179752242, 34.0980562646],
[-118.3190322094, 34.0980534784],
[-118.3196927936, 34.0980434887],
[-118.3201023859, 34.0980451522],
[-118.3205482909, 34.0980412221],
[-118.3211857744, 34.0980367814],
[-118.3221370608, 34.0980342489],
[-118.3221370608, 34.0980342489],
[-118.3223022147, 34.0980338084],
[-118.3237159212, 34.0980272813],
[-118.3251494567, 34.0980234321],
[-118.3266523459, 34.0980166305],
[-118.3269826536, 34.0980157371],
[-118.3269826536, 34.0980157371],
[-118.3277291488, 34.0980137146],
[-118.3285747363, 34.0980114181],
[-118.3285747363, 34.0980114181],
[-118.3287398901, 34.0980109688],
[-118.3295194161, 34.0980088454],
[-118.3302659112, 34.0980068073],
[-118.3308439408, 34.0980030276],
[-118.3308439408, 34.0980030276],
[-118.3310090924, 34.0980020257],
[-118.3315507967, 34.0980005405],
[-118.3321981995, 34.0979987622],
[-118.3324261117, 34.0979981354],
[-118.3331990313, 34.0979960064],
[-118.3337836755, 34.0979943928],
[-118.3351148245, 34.0979931812],
[-118.3351148245, 34.0979931812],
[-118.3352799794, 34.0979929978],
[-118.3363072466, 34.0979928908],
[-118.3365714926, 34.097992155],
[-118.3375558087, 34.0979894091],
[-118.3380083299, 34.097988144],
[-118.3384839804, 34.097988736],
[-118.3384839804, 34.097988736],
[-118.3386491374, 34.0979890976],
[-118.3404724342, 34.0979839735],
[-118.3412090286, 34.097984094],
[-118.3412090286, 34.097984094],
[-118.3413741845, 34.0979841771],
[-118.3415459444, 34.0979836917],
[-118.3424840285, 34.0979837842],
[-118.3439506338, 34.0979895105],
[-118.3439506338, 34.0979895105],
[-118.344115792, 34.0979901394],
[-118.3451926279, 34.0979953114],
[-118.3455658866, 34.0979969924],
[-118.3462463311, 34.0979977922],
[-118.3467814519, 34.0980017534],
[-118.3470093753, 34.0980038469],
[-118.3478582881, 34.0980069016],
[-118.3483306391, 34.0980082887],
[-118.3484957963, 34.0980086368],
[-118.3484957963, 34.0980086368],
[-118.3489450223, 34.0980092638],
[-118.3495561139, 34.0980129932],
[-118.349869914, 34.0980140085],
[-118.349869914, 34.0980140085],
[-118.3500350711, 34.0980143545],
[-118.350629659, 34.0980208741],
[-118.351009524, 34.0980225191],
[-118.3517329319, 34.098028659],
[-118.3526644382, 34.0980352866],
[-118.3526644382, 34.0980352866],
[-118.3528295989, 34.0980364531],
[-118.3539163685, 34.0980470141],
[-118.3550229451, 34.0980547593],
[-118.3559379366, 34.0980614101],
[-118.3559379366, 34.0980614101],
[-118.3561030974, 34.0980625722],
[-118.3561988982, 34.0980650377],
[-118.3570874606, 34.0980706586],
[-118.3572030683, 34.0980703169],
[-118.3582303246, 34.0980672756],
[-118.359254266, 34.0980614875],
[-118.3593731767, 34.0980611339],
[-118.3603475837, 34.0980582318],
[-118.3604631913, 34.098057887],
[-118.3615366904, 34.0980546796],
[-118.3618669978, 34.0980536908],
[-118.3618669978, 34.0980536908],
[-118.3628414046, 34.0980507686],
[-118.3630329829, 34.0980501932],
[-118.364284776, 34.0980299383],
[-118.3644796453, 34.0980266027],
[-118.3650312344, 34.0980194418],
[-118.3651996791, 34.0980161849],
[-118.3654771216, 34.0980117738],
[-118.3654771216, 34.0980117738],
[-118.3656422667, 34.0980093506],
[-118.3664646834, 34.0979958675],
[-118.3667024925, 34.0979923981],
[-118.3674192106, 34.0979792292],
[-118.3676536803, 34.0979675245],
[-118.3678518524, 34.0979641734],
[-118.3679310898, 34.0979556885],
[-118.3680003696, 34.0979362423],
[-118.3680696252, 34.0979113004],
[-118.3681981665, 34.0978477074],
[-118.368346405, 34.0977565754],
[-118.3686624692, 34.0975220413],
[-118.3689653558, 34.0972957903],
[-118.3692583802, 34.0970805602],
[-118.3693999979, 34.0969866992],
[-118.3695482457, 34.0968983136],
[-118.3696998327, 34.0968181612],
[-118.3699734001, 34.0966854254],
[-118.3701613073, 34.0966024133],
[-118.3703162813, 34.096541485],
[-118.3707610598, 34.0963601346],
[-118.3707610598, 34.0963601346],
[-118.3711042869, 34.0962203127],
[-118.3712097756, 34.0961732746],
[-118.3712921431, 34.0961263075],
[-118.3715622074, 34.0959496127],
[-118.3716840028, 34.09585581],
[-118.3719504691, 34.0956131762],
[-118.3720459131, 34.0955359415],
[-118.3722171907, 34.0954282465],
[-118.3722995692, 34.0953840266],
[-118.372464436, 34.0953203171],
[-118.3725304072, 34.0953003289],
[-118.3725304072, 34.0953003289],
[-118.3726854408, 34.0952536864],
[-118.3729493468, 34.0951786792],
[-118.3734179376, 34.0950810559],
[-118.3739491727, 34.0949585059],
[-118.3746981913, 34.0947885644],
[-118.3759586926, 34.0945126081],
[-118.3761500402, 34.0944625507],
[-118.3762786691, 34.0944209319],
[-118.3763775838, 34.0943821534],
[-118.3764302946, 34.0943517624],
[-118.3765027857, 34.0943130662],
[-118.3767464841, 34.0941529292],
[-118.3767514236, 34.0941496163],
[-118.3767514236, 34.0941496163],
[-118.3777640446, 34.0934765202],
[-118.3782843352, 34.0931286588],
[-118.378478608, 34.0929961519],
[-118.3790912481, 34.0926205189],
[-118.379420711, 34.0924381243],
[-118.3794391671, 34.0924292731],
[-118.3794391671, 34.0924292731],
[-118.3795822014, 34.0923606763],
[-118.3799414752, 34.0921974218],
[-118.3804755477, 34.0919786582],
[-118.3806567657, 34.0918819114],
[-118.3808149886, 34.0918127156],
[-118.3812568781, 34.0916601883],
[-118.3814745759, 34.0915962998],
[-118.3816560929, 34.0915654998],
[-118.3818639318, 34.0915126333],
[-118.3819859476, 34.0914710293],
[-118.3821903326, 34.0913851985],
[-118.3823023643, 34.0913271384],
[-118.3824769355, 34.0912221663],
[-118.3827007841, 34.0910593322],
[-118.3828720388, 34.0909516221],
[-118.3830631098, 34.0908438489],
[-118.3831567213, 34.0908026086],
[-118.3831567213, 34.0908026086],
[-118.3833465826, 34.090719295],
[-118.3834323163, 34.0906887962],
[-118.3835774874, 34.0906553608],
[-118.3836665994, 34.0906413384],
[-118.3837722379, 34.0906300113],
[-118.3838713212, 34.0906296965],
[-118.3840199841, 34.0906374678],
[-118.3844493832, 34.0906443458],
[-118.3853675658, 34.0906436188],
[-118.3853675658, 34.0906436188],
[-118.3855327072, 34.0906436415],
[-118.3865730824, 34.0906403171],
[-118.3866259522, 34.0906456437],
[-118.3874582307, 34.0906383061],
[-118.3874582307, 34.0906383061],
[-118.3876233658, 34.090636952],
[-118.3885217214, 34.0906340664],
[-118.3895785987, 34.0906281899],
[-118.3895785987, 34.0906281899],
[-118.3897437363, 34.0906273825],
[-118.3910252138, 34.0906232418],
[-118.3914446407, 34.0906163878],
[-118.3919400572, 34.0906147816],
[-118.3920522486, 34.0905924345],
[-118.392098423, 34.0905785452],
[-118.3923126393, 34.0904789259],
[-118.3924674827, 34.0903959865],
[-118.3925840588, 34.0903227887],
[-118.3925840588, 34.0903227887],
[-118.3927967915, 34.0901888248],
[-118.393158984, 34.0899513285],
[-118.3935442937, 34.0897137558],
[-118.393814355, 34.0895507505],
[-118.3941931462, 34.0893324322],
[-118.3947201556, 34.0890284441],
[-118.3951648015, 34.0887686892],
[-118.3953683993, 34.088660306],
[-118.3953683993, 34.088660306],
[-118.3955074249, 34.0885862076],
[-118.396136756, 34.0882708867],
[-118.3961598357, 34.0882625673],
[-118.3963410926, 34.0881795362],
[-118.3967136046, 34.0880326756],
[-118.396881754, 34.0879716698],
[-118.3970301133, 34.0879162247],
[-118.3975544148, 34.0877413836],
[-118.3978742632, 34.0876331631],
[-118.3979636358, 34.0876056647],
[-118.3979636358, 34.0876056647],
[-118.3981183067, 34.0875581662],
[-118.3982337165, 34.0875193155],
[-118.3992725042, 34.0871916362],
[-118.399460466, 34.0871305614],
[-118.3997639015, 34.0870443732],
[-118.4002750996, 34.0868942947],
[-118.400364139, 34.0868665208],
[-118.4009182954, 34.0867217929],
[-118.4011096498, 34.0866799395],
[-118.4013208592, 34.0866462634],
[-118.4015783184, 34.0866151811],
[-118.4019546318, 34.0865754592],
[-118.4020279288, 34.0865708187],
[-118.4020279288, 34.0865708187],
[-118.4024036553, 34.0865464856],
[-118.4028956919, 34.0865338541],
[-118.4030806383, 34.0865332372],
[-118.4032425061, 34.0865409406],
[-118.4034407823, 34.0865650097],
[-118.4043625041, 34.0866223816],
[-118.4048083176, 34.0866126449],
[-118.4050691178, 34.0865897877],
[-118.4053958503, 34.0865419776],
[-118.4058347113, 34.0864608154],
[-118.4060553798, 34.0864031927],
[-118.4060553798, 34.0864031927],
[-118.4060689031, 34.086399575],
[-118.4062502262, 34.0863330161],
[-118.4062963692, 34.0863136257],
[-118.4066490265, 34.0861640533],
[-118.4071661833, 34.0858847748],
[-118.4072320745, 34.085851578],
[-118.4076663952, 34.0855176189],
[-118.4078407052, 34.0853680951],
[-118.4078407052, 34.0853680951],
[-118.4079788394, 34.0852500191],
[-118.408274742, 34.0849769786],
[-118.408465364, 34.08478673],
[-118.4090534954, 34.0841664655],
[-118.4097075469, 34.0835212435],
[-118.4099212123, 34.083317175],
[-118.4100142551, 34.0832316747],
[-118.4100142551, 34.0832316747],
[-118.4101250502, 34.0831296268],
[-118.4103387676, 34.082936549],
[-118.4110458412, 34.0823323579],
[-118.4111313401, 34.082257874],
[-118.4115786875, 34.0818936296],
[-118.4116487561, 34.0818378835],
[-118.4116487561, 34.0818378835],
[-118.4117694844, 34.0817418456],
[-118.4119537569, 34.0816065709],
[-118.4126315741, 34.0811013942],
[-118.4132141029, 34.0806954636],
[-118.4139689644, 34.080213098],
[-118.4139689644, 34.080213098],
[-118.4141259919, 34.0801125367],
[-118.4149062654, 34.079628979],
[-118.4151565203, 34.0794824812],
[-118.4155978998, 34.0792528888],
[-118.4162961736, 34.0788850154],
[-118.4168594238, 34.0785931709],
[-118.4168594238, 34.0785931709],
[-118.4170274094, 34.0785060327],
[-118.4177290553, 34.0781546267],
[-118.4180090763, 34.0780190115],
[-118.4184473166, 34.0778251421],
[-118.4188690712, 34.077636824],
[-118.4192315898, 34.0774899284],
[-118.4198043838, 34.0772612384],
[-118.4198043838, 34.0772612384],
[-118.4199533487, 34.077201641],
[-118.4203653695, 34.0770490741],
[-118.4205500047, 34.0769907258],
[-118.4206918349, 34.0769572573],
[-118.4207578381, 34.0769487838],
[-118.4208767185, 34.0769483696],
[-118.4210220721, 34.0769588546],
[-118.4211840476, 34.0769912646],
[-118.4213329388, 34.077048451],
[-118.4215150742, 34.0771494875],
[-118.4216278352, 34.07724527],
[-118.4216909242, 34.077313747],
[-118.4217674163, 34.0774206475],
[-118.4218340849, 34.0775440697],
[-118.4219526112, 34.0778005833],
[-118.4219526112, 34.0778005833],
[-118.4226354017, 34.079277934],
[-118.4227391348, 34.0795468641],
[-118.4228259679, 34.0797389123],
[-118.4228515918, 34.0797775679],
[-118.4228515918, 34.0797775679],
[-118.4229224723, 34.0798842126],
[-118.4229357373, 34.0798951577],
[-118.4229954992, 34.0799581499],
[-118.4230717173, 34.0800100928],
[-118.4231677498, 34.0800619663],
[-118.4233829314, 34.0801656321],
[-118.4248022117, 34.080666261],
[-118.4252356476, 34.0808268614],
[-118.4254604474, 34.080872784],
[-118.4255466398, 34.0808724804],
[-118.4255466398, 34.0808724804],
[-118.4256949169, 34.080871958],
[-118.4258104585, 34.0808633071],
[-118.4269593384, 34.0807905547],
[-118.4271078475, 34.0807707945],
[-118.427394874, 34.0807148216],
[-118.4275365392, 34.080648371],
[-118.4276353436, 34.0805958114],
[-118.4277110313, 34.0805433335],
[-118.427780086, 34.0804853833],
[-118.427868744, 34.0803861454],
[-118.4280458765, 34.0801519473],
[-118.4281669102, 34.0799261915],
[-118.4281734305, 34.079909681],
[-118.4282749451, 34.0797416999],
[-118.4284193192, 34.0795598273],
[-118.4285607141, 34.0794411666],
[-118.4286495672, 34.0793803978],
[-118.4287615365, 34.0793195468],
[-118.4288636972, 34.0792779659],
[-118.4289395238, 34.0792529656],
[-118.4290219833, 34.0792334376],
[-118.4290583088, 34.0792333086],
[-118.4290813687, 34.0792222351],
[-118.4292200239, 34.0792134989],
[-118.4293686706, 34.0792212143],
[-118.4295140857, 34.0792426804],
[-118.4295934261, 34.0792588856],
[-118.4297191261, 34.0792996569],
[-118.4298647532, 34.0793623402],
[-118.4299011918, 34.0793841936],
[-118.430010536, 34.0794552496],
[-118.4300702181, 34.0795017512],
[-118.4301399303, 34.0795721238],
[-118.4301399303, 34.0795721238],
[-118.430143251, 34.0795756842],
[-118.430199744, 34.0796441802],
[-118.4302463443, 34.0797154594],
[-118.4303096825, 34.0798306451],
[-118.4303999064, 34.0800364154],
[-118.430768246, 34.0810215947],
[-118.4308520232, 34.0812576144],
[-118.43091542, 34.0813837912],
[-118.4310051939, 34.0815016301],
[-118.4312874576, 34.0818028906],
[-118.4317056904, 34.0822135801],
[-118.4318449888, 34.0823284936],
[-118.4318814575, 34.0823558421],
[-118.4320636031, 34.0824541148],
[-118.4322224756, 34.0825222437],
[-118.4324043804, 34.0825738026],
[-118.4325326165, 34.0825928536],
[-118.4325326165, 34.0825928536],
[-118.4326952237, 34.0826167275],
[-118.4336469719, 34.0827369698],
[-118.4338121804, 34.082752864],
[-118.4340235522, 34.0827548527],
[-118.4341093876, 34.0827490485],
[-118.434267763, 34.0827210003],
[-118.4343172428, 34.0827098309],
[-118.4344523581, 34.0826543873],
[-118.4344536748, 34.0826535582],
[-118.4344536748, 34.0826535582],
[-118.4345346911, 34.0826101249],
[-118.434600526, 34.0825686697],
[-118.4346498629, 34.0825300218],
[-118.4347451484, 34.0824362506],
[-118.4347877802, 34.0823783915],
[-118.434869627, 34.0822407024],
[-118.4348760032, 34.0821967132],
[-118.4349021084, 34.0821361657],
[-118.4350347783, 34.081610841],
[-118.4350733495, 34.0814073583],
[-118.4351030784, 34.0812181964],
[-118.4351030784, 34.0812181964],
[-118.4351117061, 34.0811626579],
[-118.4351410131, 34.0810828636],
[-118.4352098772, 34.0809891872],
[-118.4352721078, 34.080890039],
[-118.4352983553, 34.0808569697],
[-118.4353838168, 34.0807797208],
[-118.4354101214, 34.0807576429],
[-118.4355845895, 34.0806498462],
[-118.4356834032, 34.0806000279],
[-118.4358317094, 34.0805417872],
[-118.4362965842, 34.080394471],
[-118.4364778559, 34.0803251189],
[-118.4366754812, 34.0802254806],
[-118.4368104905, 34.0801507995],
[-118.4369191238, 34.0800844573],
[-118.4369948052, 34.0800319736],
[-118.437142736, 34.0799022876],
[-118.4374288474, 34.079673177],
[-118.4376359746, 34.0794965618],
[-118.4377379442, 34.0794192515],
[-118.4379057155, 34.0792949884],
[-118.4381558715, 34.0791374515],
[-118.4393996722, 34.0782810878],
[-118.4392701904, 34.07814966],
[-118.4391984067, 34.0780633625],
[-118.4391984067, 34.0780633625],
[-118.4391837829, 34.0780455543],
[-118.4390740001, 34.0778920716],
[-118.4390605891, 34.0778536499],
[-118.4390272203, 34.0777878218],
[-118.4390033977, 34.0776532618],
[-118.4389958557, 34.0774746764],
[-118.4390009459, 34.0771861294],
[-118.4389973552, 34.0771311847],
[-118.4389705191, 34.0770515934],
[-118.4389004368, 34.0769117057],
[-118.4388004473, 34.076736204],
[-118.4387105234, 34.0765908925],
[-118.4386837598, 34.0765250403],
[-118.4386634565, 34.0764316858],
[-118.438720965, 34.0760632597],
[-118.438719884, 34.0758571719],
[-118.4387163656, 34.0758159664],
[-118.4386861559, 34.0757226478],
[-118.4386658384, 34.0756265455],
[-118.438629039, 34.0755359988],
[-118.4385522965, 34.0753851435],
[-118.4384523096, 34.0752096415],
[-118.437970648, 34.0742259958],
[-118.437970648, 34.0742259958],
[-118.4379082308, 34.07409872],
[-118.4374546015, 34.0732320307],
[-118.4372542787, 34.072812329],
[-118.4372341934, 34.0727601918],
[-118.4372104326, 34.0726366228],
[-118.4371927733, 34.0724168556],
[-118.4371984438, 34.0722382223],
[-118.4372078473, 34.0721420121],
[-118.437227085, 34.0720320269],
[-118.4372857747, 34.0718889243],
[-118.437361003, 34.0717512574],
[-118.4374856464, 34.0715914285],
[-118.4375545863, 34.0715142379],
[-118.4376958685, 34.0713790794],
[-118.4378899103, 34.0712299901],
[-118.4381926583, 34.0710310442],
[-118.4382814091, 34.0709537813],
[-118.4383997769, 34.0708571756],
[-118.4384688018, 34.0707964715],
[-118.4385509193, 34.0707137367],
[-118.4386198431, 34.0706337977],
[-118.4386624662, 34.0705759372],
[-118.4387115203, 34.0704850787],
[-118.4387408345, 34.0704080314],
[-118.4389315415, 34.0696241901],
[-118.4389971591, 34.0693549334],
[-118.4389971591, 34.0693549334],
[-118.4391060815, 34.0689063567],
[-118.43913179, 34.0687716167],
[-118.4391411908, 34.0686754064],
[-118.4391660751, 34.0677547732],
[-118.4392107431, 34.0674578388],
[-118.4392169861, 34.0673891189],
[-118.4392427228, 34.0672598745],
[-118.4392850263, 34.0671415615],
[-118.4393143965, 34.0670755053],
[-118.4393863298, 34.0669405971],
[-118.4394256198, 34.0668772527],
[-118.4394321773, 34.0668684356],
[-118.4394321773, 34.0668684356],
[-118.4395961021, 34.0666458097],
[-118.4397927958, 34.0663758006],
[-118.4399531539, 34.0661031756],
[-118.4400348751, 34.0659462483],
[-118.4400707611, 34.0658636808],
[-118.4401650817, 34.0655912962],
[-118.4401879339, 34.0655417509],
[-118.4402567507, 34.0654425761],
[-118.440296184, 34.0654067098],
[-118.4405593708, 34.0652243894],
[-118.4407336406, 34.0650863592],
[-118.4407960121, 34.0650174344],
[-118.4408255108, 34.0649761084],
[-118.4408680281, 34.0648990123],
[-118.4408973239, 34.0648192166],
[-118.4409167144, 34.064739457],
[-118.4409261996, 34.0646597336],
[-118.4409616498, 34.0644947309],
[-118.4410654075, 34.0641343786],
[-118.4410750229, 34.0640793857],
[-118.4412665372, 34.0640814341],
[-118.441404148, 34.0640674666],
[-118.441404148, 34.0640674666],
[-118.4414909383, 34.0640586309],
[-118.4416228911, 34.0640361654],
[-118.4417350045, 34.0640082765],
[-118.4418305802, 34.0639749522],
[-118.4420710393, 34.0638669047],
[-118.4422028755, 34.0638224558],
[-118.4423479474, 34.0637834542],
[-118.4424271012, 34.0637666769],
[-118.4425557225, 34.0637387268],
[-118.4427510731, 34.0637171269],
[-118.4427510731, 34.0637171269],
[-118.4427603121, 34.0637159938],
[-118.4429188086, 34.0637181606],
[-118.4430674437, 34.063728607],
[-118.4432655753, 34.0637333757],
[-118.44347687, 34.0637298522],
[-118.4441007178, 34.0636945852],
[-118.444305409, 34.0636910845],
[-118.4449426967, 34.06369973],
[-118.4453355852, 34.063695534],
[-118.4453650159, 34.0627116813],
[-118.4453650159, 34.0627116813],
[-118.4453692369, 34.0625742713],
[-118.4459338797, 34.0625831793],
[-118.4461353398, 34.0625934269],
[-118.4464259301, 34.0626005968],
[-118.446769303, 34.0625993271],
[-118.4468880895, 34.0625851482],
[-118.447029826, 34.0625406574],
[-118.4471056027, 34.0625101501],
[-118.447210962, 34.0624548023],
[-118.4477244616, 34.0621616235],
[-118.4479846, 34.0620315081],
[-118.4480450303, 34.0622181404],
[-118.448125256, 34.0624019513],
[-118.4482651329, 34.0626267591],
[-118.4483052388, 34.0627172906],
[-118.448332197, 34.0628188625],
[-118.4483358669, 34.0628875461],
[-118.4483427059, 34.0629314869],
[-118.4483366621, 34.0630359291],
[-118.4482662485, 34.0634511218],
[-118.4482408362, 34.0636380726],
[-118.4479110636, 34.0636519363],
[-118.4479110636, 34.0636519363],
[-118.4475971362, 34.0636651908],
[-118.447058973, 34.0636699319],
[-118.4467287702, 34.0636651084]]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.drawPolyline()
}
func drawPolyline() {
//Step 1:
let coordinates = self.geoJson.map({CLLocationCoordinate2D(latitude: $0.last!, longitude: $0.first!)})
//Step 2:
let chunkSize = 3
let chunkedCoordinates = coordinates.chunked(into: chunkSize)
//Step 3:
let path = GMSMutablePath()
//Step 4:
for chunk in chunkedCoordinates {
for coordinate in chunk {
path.add(coordinate)
}
if chunk.count == 3 {
let location1 = CLLocation(latitude: chunk[1].latitude, longitude: chunk[1].longitude)
let location2 = CLLocation(latitude: chunk[2].latitude, longitude: chunk[2].longitude)
if !GMSGeometryIsLocationOnPath(chunk[1], path, false) ||
!GMSGeometryIsLocationOnPath(chunk[2], path, false) ||
location2.distance(from: location1) < 1.5 {
continue
}
let angle = GMSGeometryHeading(chunk[1], chunk[2])// chunk[1].heading(to: chunk[2])
var arrowImage = UIImage(named: "icon_navigation")!
arrowImage = arrowImage.withColor(UIColor.orange.withAlphaComponent(0.8))
let marker = GMSMarker(position: chunk[1])
marker.icon = arrowImage
marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)
marker.isFlat = true
marker.rotation = angle
marker.map = self.mapView
}
}
//Step 5:
let polyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor.orange
polyline.strokeWidth = 5.0
polyline.map = self.mapView
//Step 6:
let bounds = GMSCoordinateBounds(path: path)
self.mapView.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 50.0))
}
}
extension Array {
func chunked(into size: Int) -> [[Element]] {
return stride(from: 0, to: count, by: size).map {
Array(self[$0 ..< Swift.min($0 + size, count)])
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment