How to display a subview or button at the top of Google maps Xcode

I tried to add a button on top of google maps. I tried everything I could, but no help can help me. In the Xcode preview, it appears on top, but after launching the application, it appears below the google map.

Image after application launch

Image after application launch

What does it look like in Xcode

How it looks in Xcode

MAP CODE

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()

    }
}



}
+4
source share
2 answers

I found the answer

self.view.bringSubviewToFront(self.view_name)

You need to call showSubviewToFront on the parent view.

+5
source

Are you using the method below? If so, make sure you give the frame to mapview, so try to provide the frame as you would in the storyboard.

[GMSMapView mapWithFrame: (CGRect) : (GMSCameraPosition *)];

0

Source: https://habr.com/ru/post/1612760/


All Articles