【问题标题】:Adding marker on Google maps在谷歌地图上添加标记
【发布时间】:2016-03-16 15:29:05
【问题描述】:

这可能是一个重复的问题(写之前看了很多答案),但我无法解决它。

我想简单地将谷歌地图集成到我的 swift 应用程序中。除了让那个标记显示在地图上之外,一切都很好。我正在关注谷歌地图 api 文档,但没有运气。

这是函数的主体:

// Do any additional setup after loading the view.

        /**Testing Google Maps **/
        let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
            longitude: 151.20, zoom: 6)
        //let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
        googleMapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)



        let  position = CLLocationCoordinate2DMake(10, 10)
        let marker = GMSMarker(position: position)
        marker.title = "Hello World"
        marker.map = googleMapView

这是在 viewDidLoad() 中执行的。我让地图显示,但它没有显示任何标记。

感谢您的帮助。

【问题讨论】:

    标签: ios swift google-maps-api-3 google-maps-markers


    【解决方案1】:

    此代码适用于我:

    var marker = GMSMarker()
    marker.postion = CLLocationCoordinate2DMake(10,10)
    marker.title ="ENTER TITLE"
    marker.snippet ="ENTER SNIPPET"
    marker.map = googleMapView
    

    希望这会有所帮助:)

    【讨论】:

      【解决方案2】:

      经过长时间的尝试和研究,通过调整一行来获得与 GMSMap 类型的 UIView 中相同的地图视图:

      let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
                  longitude: 151.20, zoom: 6)
              googleMapView.camera = camera //This line
              googleMapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
      

      【讨论】:

        【解决方案3】:

        你在viewDidLoad中设置了mapView的代理吗

        mapView.delegate = self
        

        并像这样在您的ViewController 中接受GMSMapViewDelegate 协议

        class ViewController: UIViewController, GMSMapViewDelegate {
        }
        

        【讨论】:

          猜你喜欢
          • 2015-08-18
          • 1970-01-01
          • 2020-10-12
          • 1970-01-01
          • 1970-01-01
          • 2017-12-25
          • 2018-05-11
          • 2018-12-09
          相关资源
          最近更新 更多