ios - Creating markers in GoogleMaps -


how create function drawing markers on map array of applications received during operation. is, function must outside viewdidload() ? if use simple function following content:

import uikit  import googlemaps  import corelocation    class viewcontroller: uiviewcontroller {    @iboutlet var mmap: gmsmapview!    let locationmanager = cllocationmanager()  let mapinsets = uiedgeinsets(top: 10.0, left: 0.0, bottom: 100.0, right: 0.0)    override func viewdidload() {          super.viewdidload()        view = mmap      mmap.padding = mapinsets       mmap.ismylocationenabled = true       mmap.settings.compassbutton = true       mmap.settings.mylocationbutton = true       mmap.settings.scrollgestures = true      mmap.settings.zoomgestures = true        let camera = gmscameraposition.camera(withlatitude: mylat, longitude: mylon, zoom: 15.0)      let mmap = gmsmapview.map(withframe: cgrect.zero, camera: camera)         let buttondps = uibutton(frame: cgrect(x: 2, y: 520, width: 103, height: 45))      button.backgroundcolor = .red      button.settitle("yes", for: .normal)      button.titlelabel!.font = uifont.boldsystemfont(ofsize: 19)      button.layer.cornerradius = 5.0         button.addtarget(self, action: #selector(buttonact), for:.touchupinside)      self.view.addsubview(button)    }    func buttonact(sender: uibutton!) {              let alert = uialertcontroller(title:"help", message:"qwerty", preferredstyle:.alert)      alert.addaction(uialertaction(title:"ok", style:.default){ action in      self.markercreate()                              })      alert.addaction(uialertaction(title:"cancel", style:.cancel, handler:nil))      self.present(alert, animated:true, completion:nil)        }          func markercreate(){              let marker2 = gmsmarker()              marker2.position = cllocationcoordinate2d(latitude: 54.9044200,             longitude: 52.3154000)              marker2.title = "Россия"              marker2.snippet = "Москва"              marker2.map = mmap          }  }

then nothing happens (((

as far can analyze,

the code work fine. marker added map. you don't see marker have added. move camera position of map marker position can see marker, i.e.

func markercreate() {     //your code...     mmap.camera = gmscameraposition.camera(withlatitude: 54.9044200, longitude: 52.3154000, zoom: 15.0) //add line code } 

i assume resolve 2 mmap variables have created mentioned in comment.

edit:

1. in storyboard, set viewcontroller's view's class gmsmapview , connect outlet mmap it, i.e.

enter image description here

2. follow comments in below code snippet:

override func viewdidload() {     super.viewdidload()      //your code...      view = mmap //remove line     mmap.camera = gmscameraposition.camera(withlatitude: 54.9044200, longitude: 52.3154000, zoom: 15.0) //add line     let camera = gmscameraposition.camera(withlatitude: mylat, longitude: mylon, zoom: 15.0) //remove line     let mmap = gmsmapview.map(withframe: cgrect.zero, camera: camera) //remove line      //your code... } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -