Swift 4:不显示多个标记Google Map

时间:2018-02-27 08:09:48

标签: ios swift google-maps

我正在开发一个具有多个位置/标记的应用。

我创建了一个结构

let states = [
    State(name: "Zoo 1", long: 2.276537, lat: 102.2989),
    State(name: "Zoo 2", long: 2.2772141, lat: 102.2984333),
    // the other 51 states here...
]

并尝试循环,但标记未显示

for state in states {
        let state_marker = GMSMarker()
        state_marker.position = CLLocationCoordinate2D(latitude: state.lat, longitude: state.long)
        state_marker.title = state.name
        state_marker.snippet = "Hey, this is \(state.name)"
        state_marker.map = mapView
    }

当我喜欢下面的内容时,它正在发挥作用。但我知道这不是一个更好的方式

let state_marker = GMSMarker()
    state_marker.position = CLLocationCoordinate2D(latitude: 2.276622, longitude: 102.2989)
    state_marker.title = "Zoo 1"
    state_marker.snippet = "Hey, this is Zoo 1"
    state_marker.map = mapView

    let state_marker1 = GMSMarker()
    state_marker1.position = CLLocationCoordinate2D(latitude: 2.2772141, longitude: 102.2984333)
    state_marker1.title = "Zoo 2"
    state_marker1.snippet = "Hey, this is Zoo 2"
    state_marker1.map = mapView

有人知道我的代码有什么问题吗?

0 个答案:

没有答案