【发布时间】:2016-06-23 06:52:35
【问题描述】:
我试图弄清楚为什么我的谷歌地图视图只在屏幕上显示一个标记,即使获取数据有 2 条记录。我使用领域来存储每个位置的纬度和经度。即使我的领域有两个标记位置,为什么它只掉一个标记,有帮助吗?
@IBOutlet weak var mapView: GMSMapView!
var locationMarker: GMSMarker!
var locationList : Results<TowerLocationList>!
@IBAction func findAddress(sender: AnyObject) {
// Clearing all marker to protect duplicate marker drop
self.mapView.clear()
//Fetching all marker from realm object
locationList = realm.objects(TowerLocationList)
print("The list included at Realm DB is : \(locationList)")
print("List count : \(locationList.count)")
for var i = 0 ; i < locationList.count; i++ {
let coordinate = CLLocationCoordinate2D(latitude: Double(locationList[i].latitude)!, longitude: Double(locationList[i].longitude)!)
self.setupLocationMarker(coordinate)
print("For Loop i : \(i)")
}
}
func setupLocationMarker(coordinate: CLLocationCoordinate2D) {
locationMarker = GMSMarker(position: coordinate)
locationMarker.map = mapView
locationMarker.appearAnimation = kGMSMarkerAnimationPop
locationMarker.icon = UIImage(named: "Radio_Tower")
//locationMarker.opacity = 0.75
locationMarker.flat = true
locationList = realm.objects(TowerLocationList).filter("longitude = '\(coordinate.longitude)' AND latitude = '\(coordinate.latitude)'")
locationMarker.snippet = locationList[0].siteCode
print(locationMarker.snippet)
}
当我点击 findAddress 按钮时, 输出是:
The list included at Realm DB is : Results<TowerLocationList> (
[0] TowerLocationList {
siteCode = AY0121;
longitude = 96.1265519633889;
latitude = 16.8548376155088;
},
[1] TowerLocationList {
siteCode = AY0119;
longitude = 96.1268738284707;
latitude = 16.8490258657804;
}
)
List count : 2
Optional("AY0121")
For Loop i : 0
为什么循环在索引 0 处停止而不转到索引 1?
【问题讨论】:
标签: swift google-maps google-maps-markers