本文介绍了GMSMarker没有出现在地图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
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.map = mapView
让marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86,151.20)
marker.title =title
marker.snippet =snippet
标记。 map = mapView
:'self.map = mapView'如果我写'self.view = mapView'它会正常工作,并显示我的标记。但是我在页面中还有其他视图以及mapView,'self.view = mapView'会隐藏它们。相机也去坐标。唯一的问题是标记没有出现。
我应该怎么做?谢谢
解决方案
我在Google搜索结束后解决了这个问题。关键是在mainView中使用 Container View ,并在containerView中使用以下代码初始化映射:
var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude:151.20,zoom:6)
var mapView = GMSMapView.mapWithFrame(CGRectZero,camera:camera)
mapView .myLocationEnabled = true
self.map.camera =相机
self.view = mapView
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86,151.20)
marker.title =title
marker.snippet =snippet
marker.map = mapView
In swift, I want to show a google-map with a marker on it.
here's storyboard image:
and here's the code
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.map = mapView
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "title"
marker.snippet = "snippet"
marker.map = mapView
in the line: 'self.map = mapView' if I write 'self.view = mapView' it will work fine and shows me the marker. but I have other views in the page along with mapView and 'self.view = mapView' will hide them. camera goes to the coordniates also. the only problem is that the marker is not appearing.
what should I do? thanks
解决方案
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没有出现在地图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!