在Swift中,我下载了位置数据并在Google地图上设置了一个标记,但标记并未出现在地图上。谷歌地图GMSMarker没有出现在地图上
数据项:
init(id: Int?,name: String?, owner: String?, address: String?, lon: String!, lat: String!, phoneNum: String?) {
self.id = id
self.name = name
self.owner = owner
self.address = address
self.phoneNum = phoneNum
self.lon = Double(lon)
self.lat = Double(lat)
self.coordinate = CLLocationCoordinate2DMake(self.lat, self.lon)
}
设置标记(标记不会出现在地图上):
let data = UserData.shareInstance()
for item in data.itemsArray {
let marker = GMSMarker()
marker.position = item.coordinate
marker.title = item.name!
marker.map = mapView
}
但是,如果我创建与当前位置的假的位置,并设置标志,它出现在地图上:
for i in 0...1 {
let marker = GMSMarker()
switch i {
case 0:
marker.position = CLLocationCoordinate2DMake(self.currentLocation.coordinate.latitude + 0.01, currentLocation.coordinate.longitude)
break
case 1:
marker.position = CLLocationCoordinate2DMake(self.currentLocation.coordinate.latitude - 0.001, currentLocation.coordinate.longitude)
break
default:
break
}
marker.title = "test"
marker.map = mapView
}
为什么?
Does itemsArray是否包含任何元素? – PGDev
itemsArray contains dataItem – Victor
我创建一个新项目,有同样的问题... – Victor