Gmsmarker Not Appearing on Map

Google Maps GMSMarker not appearing on map

As per the Google Map Integration in iOS Swift 3. Adding a Map With Marker.

import UIKit
import GoogleMaps

class ViewController: UIViewController {

override func loadView() {

// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView

// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}
}

GMSMarker not appearing on map

I solved the problem after hours googling. the key is to use Container View inside the mainView and in the containerView initializing the map with these codes:

 var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)

var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true

self.map.camera = camera
self.view = mapView

let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "title"
marker.snippet = "snippet"
marker.map = mapView

GMSMarker not showing in 1.3

It looks like there is a bug on Google's side. I just stopped using my CustomPlayerAnnotation or GMSMarker, and used a GMSGroundOverlay instead. That showed up on the map. Then instead of using the type, tag, and coordinatePair I built into CustomPlayerAnnotation, I just relied on the title.

playerAnnotation = [[GMSGroundOverlay groundOverlayWithPosition:coord icon:[UIImage imageNamed:@"Down1.png"]] retain];
[playerAnnotation setZoomLevel:zoomLevel];
[playerAnnotation setAnchor:ccp(.5f, 1)];
[playerAnnotation setTitle:@"Player"];
[playerAnnotation setMap:gameMapView];

Side note: notice that I had to setAnchor:ccp(.5f, 1). When it was set to (.5f, .5f) the playerAnnotation overlay would cut off the bottom of the overlay when overlapping other GMSGroundOverlays. Changing the Anchor fixed the z drawing. It looks like 1.4 that just came out may have z-ordering fixed, but 1.4 broke something else on mine so I'll stick with 1.3.1 for now.

swift google maps will not show snippet window

I had to remove the delegate below in order for the infowindow to show.

//    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
// print("marker Tapped")
//
// return true
// }


Related Topics



Leave a reply



Submit