Token not found on google map in subview IOS SWIFT

Hi, I tried to put the map in subview, but when I put the google map in under the view, it does not work. GPS marker and coordinates do not work.

- With a preview With Sub View

-In unattended No Sub View

-SWIFT CODE

import UIKit
import GoogleMaps

class HomeViewController: UIViewController, CLLocationManagerDelegate {

    @IBOutlet weak var mapView: GMSMapView!

    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        locationManager.delegate = self
        locationManager.requestAlwaysAuthorization()

                let camera = GMSCameraPosition.cameraWithLatitude(15.4989, longitude: 73.8278, zoom: 6)
                let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
                mapView.myLocationEnabled = true
//                self.view = mapView
                self.view.addSubview(mapView)
                let marker = GMSMarker()
                marker.position = CLLocationCoordinate2DMake(15.4989, 73.8278)
                marker.title = "Panjim"
                marker.snippet = "Near Don Bosco,Alphran Plaza"
                marker.map?.addSubview(mapView)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

Thanks in advance

+3
source share
4 answers

Here is the solution to add a marker

            let marker = GMSMarker()
            marker.position = CLLocationCoordinate2DMake(lat, long)
            marker.appearAnimation = kGMSMarkerAnimationPop
            marker.title = "Marker" // Marker title here
            marker.snippet = "Tap the ↱ Navigate button to start navigating."
            marker.infoWindowAnchor = CGPoint(x: 0.5, y: 0)
            marker.icon = UIImage(named: "marker") //Set marker icon here
            marker.map = self.mapView // Mapview here

Camera animation in position

    let camera = GMSCameraPosition.camera(withLatitude: 15.4989, longitude: 73.8278, zoom: 17)
    mapView.animate(to: camera)
+3
source

I have found a solution. The problem was this: I created a new map, and then added a marker to this new map. Then I did nothing with the new card. So here is my solution:

@IBOutlet weak var subviewMap: GMSMapView!

func loadMap() {
        let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 10.0)
        subviewMap.camera = camera
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
        marker.title = "Sydney"
        marker.snippet = "Australia"
        marker.map = subviewMap
    }

And it works.

NOTE. Remember to mention your view as a GMSMapView class in IB

@O-mkar @mixth .

:]

+5

I have my GMSMapView inside another UIView and everything is working fine. Just another line:

marker.map = mapView
+1
source
after adding marker you should add some delay with this approach i have added 2 marker with bounds 

DispatchQueue.main.async {
            if self.markerArray.count > 1 {
                var bounds = GMSCoordinateBounds()
                for marker in self.markerArray {
                    marker.map = self.mapView
                    bounds = bounds.includingCoordinate(marker.position)
                }
                self.isMovedTheMap = false
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.9, execute: {
                    self.superTopView.fadeOut()
                    let update = GMSCameraUpdate.fit(bounds, withPadding: 80)
                    self.mapView.animate(with: update)
                })
            }
        }
0
source

All Articles