I have the following setup on one of my pages:
The current page displays a mapView with Google Maps and I pretend to display the UIView on top of the mapView... I've tried anything but the mapView always displays on top of the UIView. How can I fix this?
This is my page code:
import UIKit
import CoreLocation
import GoogleMaps
import GooglePlaces
class GoogleMapPage: UIViewController, CLLocationManagerDelegate{
var placesClient: GMSPlacesClient!
var addressName: String? = nil
lazy var geocoder = CLGeocoder()
var latitude: Double = 0.0
var longitude: Double = 0.0
@IBOutlet weak var mapView: GMSMapView!
@IBOutlet weak var cameraButton: UIButton!
@IBOutlet weak var menuButton: UIButton!
@IBOutlet weak var sideMenu: UIView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestLocation()
placesClient = GMSPlacesClient.shared()
mapView.bringSubviewToFront(cameraButton)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
if let location = locations.first {
createMap(location.coordinate.longitude, location.coordinate.latitude)
self.longitude = location.coordinate.longitude
self.latitude = location.coordinate.latitude
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
let alertController = UIAlertController(title: "Location Error", message: error.localizedDescription, preferredStyle: .alert)
let okayAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(okayAction)
self.present(alertController, animated: true, completion: nil)
}
func createMap(_ longitude: Double, _ latitude: Double){
let position = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
let marker = GMSMarker(position: position)
let camera = GMSCameraPosition.camera(withLatitude: latitude, longitude: longitude, zoom: 12.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
marker.map = mapView
marker.title = "Your Position"
mapView.addSubview(cameraButton)
mapView.addSubview(menuButton)
view = mapView
let location = CLLocation(latitude: latitude, longitude: longitude)
// Geocode Location
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
// Process Response
print(placemarks as Any)
}
}
}
Your are adding MenuView and buttons inside MapView, not top off the map view. MenuView is subview of Mapview thats why it is not showing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.