ios - drop pin with long touch in google maps -


i can't add marker long touch in google maps in swift have try lots of codes doesn't work me should !?

override func viewdidload() {      super.viewdidload()             gmsservices.provideapikey("aizasybw95wehcsisbmpwuykik0_ibnzqk-lm7i")       locationmanager.delegate = self     locationmanager.requestwheninuseauthorization()     locationmanager.desiredaccuracy = kcllocationaccuracybest     locationmanager.startupdatinglocation() }  func locationmanager(manager: cllocationmanager, didfailwitherror error: nserror) {     print("error" + error.description) }  func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) {     let userlocation = locations.last     let center = cllocationcoordinate2d(latitude: userlocation!.coordinate.latitude, longitude: userlocation!.coordinate.longitude)      let camera = gmscameraposition.camerawithlatitude(userlocation!.coordinate.latitude,                                                       longitude: userlocation!.coordinate.longitude, zoom: 16)     let mapview = gmsmapview.mapwithframe(cgrectzero, camera: camera)     mapview.mylocationenabled = true     mapview.settings.mylocationbutton = true     view = mapview     let  position = cllocationcoordinate2dmake(10, 10)     let marker = gmsmarker(position: position)       marker.opacity = 0.6     marker.position = center     marker.title = "current location"     marker.snippet = ""     marker.map = mapview     //mapview.clear() } 

ant appreciate

have try this. first need add long gesture on mapview this

for objective c

uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(handlelongpress:)]; [self.mapview addgesturerecognizer:self.longpress]; 

now add handlelongpress function

- (void)handlelongpress:(uilongpressgesturerecognizer *)recognizer {     if (recognizer.state == uigesturerecognizerstatebegan)     {         cgpoint longpresspoint = [recognizer locationinview:self.mapview];         cllocationcoordinate2d coordinate = [mapview.projection coordinateforpoint: point];         //now have coordinate of map add marker on location      } } 

for swift

let longpressrecognizer = uilongpressgesturerecognizer(target: self, action: "handlelongpress:") self.mapview.addgesturerecognizer(longpressrecognizer) 

now add handlelongpress function

func handlelongpress(recognizer: uilongpressgesturerecognizer) {     if (recognizer.state == uigesturerecognizerstate.began)     {         let longpresspoint = recognizer.locationinview(self.mapview);         let coordinate = mapview.projection.coordinateforpoint(longpresspoint )         //now have coordinate of map add marker on location         let marker = gmsmarker(position: coordinate)         marker.opacity = 0.6         marker.position = center         marker.title = "current location"         marker.snippet = ""         marker.map = mapview     } } 

hope you


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -