gpt4 book ai didi

ios - swift 4 : multiple marker Google Map not display

转载 作者:可可西里 更新时间:2023-11-01 01:09:20 26 4
gpt4 key购买 nike

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

我创建了一个结构

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

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

最佳答案

您在第一次尝试时交换了纬度和经度,在经度为 102.2989 时第二次成功,但首先您交换了它们

 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 states = [
State(name: "Zoo 1", long:102.2989 , lat: 2.276537),
State(name: "Zoo 2", long:102.2984333 , lat: 2.2772141),
// the other 51 states here...
]

编辑:

纬度测量范围从 0° 到 (+/–)90°。经度衡量一个地方位于本初子午线以东或以西的距离。本初子午线穿过英格兰的格林威治。经度测量范围从 0° 到 (+/–)180°

关于ios - swift 4 : multiple marker Google Map not display,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49003950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com