Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

How to load Google map styling from json file for ios swift?

import UIKit
import GoogleMaps

class MapView: UIView {

    @IBOutlet var contentView: UIView!

    //MARK: OVerride
    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()

    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()

    }

    //MARK: Property
    private func commonInit() {
        Bundle.main.loadNibNamed("MapView", owner: self, options: nil)
        setupMap()
        addSubview(contentView)
        contentView.frame = self.bounds

        }
 func setupMap() {
        let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        mapView.settings.myLocationButton = true

        mapView.delegate = self as! GMSMapViewDelegate
        contentView = mapView

        //style map
        do{
            if let styleURL = Bundle.main.url(forResource: "style", withExtension: "json")
            {
               mapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)
            }else{
                print("unable to find style.json")
            }
        }catch{
            print("One or more of the map styles failed to load.(error)")
        }

    }
Comment

PREVIOUS NEXT
Code Example
Swift :: Swift Variables names must start with either a letter 
Swift :: swift optionals 
Swift :: bzxjhjgvjgvjgvjv 
Swift :: Swift Syntax of Nested Function 
Swift :: Swift Check if two sets are equal 
Swift :: swift computed property 
Swift :: swift 5 cancel or end block operation 
Swift :: swift overlay view 
Swift :: Swift Add Elements to a Dictionary 
Swift :: swift function parameters 
Swift :: Swift Check if an Array is Empty 
Swift :: underline text in storyboard xcode 
Ruby :: ruby struct 
Ruby :: rails resources except 
Ruby :: rails validate uniqueness 
Ruby :: how to check ruby version 
Ruby :: ruby reference a file in a gem 
Ruby :: ruby hash transform keys 
Ruby :: ruby trim spaces 
Ruby :: ruby find index of element in array 
Ruby :: ruby max 2 numbers 
Ruby :: ruby global variable 
Ruby :: array to hash ruby 
Ruby :: ruby latest version 
Ruby :: remove ascii characters from string ruby 
Ruby :: What does inject in ruby do 
Ruby :: DEPRECATION WARNING: Sprockets method `register_engine` is deprecated. 
Ruby :: ruby abs function programming 
Ruby :: ruby sort method 
Ruby :: rails humanize date 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =