在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