【问题标题】:Make Info window Marker Google Maps Always Appear Swift使信息窗口标记谷歌地图总是出现斯威夫特
【发布时间】:2017-07-12 14:28:34
【问题描述】:

我有点击后显示的信息窗口,但如何让它始终出现?无需用户点击标记。我正在使用谷歌地图。

这是我的代码:

    mapView.delegate = self
    let camera = GMSCameraPosition.camera(withLatitude: coordinate.lat, longitude: coordinate.long, zoom: 20)
    mapView.animate(to: camera)

    for state in states {
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2DMake(state.lat, state.long)
        print(marker.position)
        marker.title = "Country"
        marker.snippet = "Places"
        marker.map = mapView
        mapView.selectedMarker = marker
        marker.map = mapView

    }

感谢之前

【问题讨论】:

    标签: swift google-maps


    【解决方案1】:

    首先我们需要添加一个标记。

    let position = CLLocationCoordinate2D(latitude: 10, longitude: 10)
    let marker = GMSMarker(position: position)
    marker.title = "Hello World"
    marker.map = mapView
    

    我们可以通过以下方式自定义标记图像:-

    let position = CLLocationCoordinate2D(latitude: 51.5, longitude: -0.127)
    let london = GMSMarker(position: position)
    london.title = "London"
    london.icon = UIImage(named: "house")
    london.map = mapView
    //To change the Marker Opacity use below
    marker.opacity = 0.6
    

    旋转标记:-

    let position = CLLocationCoordinate2D(latitude: 51.5, longitude: -0.127)
    let degrees = 90.0
    let london = GMSMarker(position: position)
    london.groundAnchor = CGPoint(x: 0.5, y: 0.5)
    london.rotation = degrees
    london.map = mapView
    

    添加信息窗口:-

    let position = CLLocationCoordinate2D(latitude: 51.5, longitude: -0.127)
    let london = GMSMarker(position: position)
    london.title = "London"
    london.snippet = "Population: 8,174,100"
    london.map = mapView
    

    设置信息窗口自动刷新

    marker.tracksInfoWindowChanges = true
    

    更改信息窗口的位置

    let position = CLLocationCoordinate2D(latitude: 51.5, longitude: -0.127)
    let london = GMSMarker(position: position)
    london.title = "London"
    london.snippet = "Population: 8,174,100"
    london.infoWindowAnchor = CGPoint(x: 0.5, y: 0.5)
    london.icon = UIImage(named: "house")
    london.map = mapView
    

    更多详情可以去Here

    【讨论】:

      【解决方案2】:

      尝试将 mapView.selectedMarker = marker 移动到委托函数 mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool 函数

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多