O-mkar O-mkar - 7 months ago 67
Swift Question

How to display sub view or button on top of Google maps Xcode

I was trying to add a button on top of Google maps. i tried everything i could but no help can anyone help me.. in Xcode preview it shows on top but after running the app it come below google map.


Picture after running app


Picture after running app


How it looks in XCODE


How it looks in XCODE


CODE OF MAP


import UIKit
import GoogleMaps

class HomeViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var scrollView: UIScrollView!
@IBAction func refreshLocation(sender: AnyObject) {
locationManager.startUpdatingLocation()

}
@IBOutlet weak var gMapView: GMSMapView!


let locationManager = CLLocationManager()




override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
self.scrollView.contentSize=CGSizeMake(320, 700)


let camera = GMSCameraPosition.cameraWithLatitude(15.4989, longitude: 73.8278, zoom: 17)

gMapView.camera = camera
gMapView.myLocationEnabled = true

self.view.addSubview(gMapView)
let marker = GMSMarker()

marker.map = self.gMapView

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

}

extension HomeViewController {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == CLAuthorizationStatus.AuthorizedAlways {
locationManager.startUpdatingLocation()

gMapView.myLocationEnabled = true

gMapView.settings.myLocationButton = true
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
gMapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)

locationManager.stopUpdatingLocation()

}
}



}

Answer

I found the answer

self.view.bringSubviewToFront(self.view_name)

You need to call bringSubviewToFront on the parent view.