ios - Fit entire Google Map in zoom level in Swift project -
i have google map bunch of coordinates
path.addcoordinate(cllocationcoordinate2dmake(-37.813047, 144.959911)) path.addcoordinate(cllocationcoordinate2dmake(-37.814895, 144.960759)) path.addcoordinate(cllocationcoordinate2dmake(-37.814361, 144.963140)) path.addcoordinate(cllocationcoordinate2dmake(-37.812386, 144.962239))
i map automatically zoomed best level based on points can't find relating this.
i have working:
var vancouver = cllocationcoordinate2dmake(-37.813047, 144.959911) var calgary = cllocationcoordinate2dmake(-37.814361, 144.963140) var bounds = gmscoordinatebounds(coordinate: vancouver, coordinate: calgary) var camera = viewmap.cameraforbounds(bounds, insets:uiedgeinsetszero) viewmap.camera = camera
however accepts 2 coordinates may have 100
thanks
you can use gmscoordinatebounds(path:)
fit coordinates. display world size scale
if update camera right after update. can use dispatch_after
solve problem.
override func viewdidload() { super.viewdidload() self.view.backgroundcolor = uicolor.whitecolor(); let camera = gmscameraposition.camerawithlatitude(-37.813047, longitude: -72.8561644, zoom:5) mapview = gmsmapview.mapwithframe(cgrectzero, camera:camera) let marker = gmsmarker() marker.position = camera.target marker.snippet = "hello world" marker.appearanimation = kgmsmarkeranimationpop marker.map = mapview self.view = mapview delay(seconds: 2) { () -> () in let path = gmsmutablepath() path.addcoordinate(cllocationcoordinate2dmake(37.36, -122.0)) path.addcoordinate(cllocationcoordinate2dmake(37.45, -122.0)) path.addcoordinate(cllocationcoordinate2dmake(37.45, -122.2)) path.addcoordinate(cllocationcoordinate2dmake(37.36, -122.2)) path.addcoordinate(cllocationcoordinate2dmake(37.36, -122.0)) let rectangle = gmspolyline(path: path) rectangle.map = self.mapview let bounds = gmscoordinatebounds(path: path) self.mapview!.animatewithcameraupdate(gmscameraupdate.fitbounds(bounds, withpadding: 15.0)) } }
the delay
method uses dispatch_after
:
func delay(#seconds: double, completion:()->()) { let poptime = dispatch_time(dispatch_time_now, int64( double(nsec_per_sec) * seconds )) dispatch_after(poptime, dispatch_get_main_queue()) { completion() } }
Comments
Post a Comment