In Swift, I download location data and set a marker on Google Maps, but the marker does not appear on the map.
Data item:
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)
}
Set marker (marker does not appear on the map):
let data = UserData.shareInstance()
for item in data.itemsArray {
let marker = GMSMarker()
marker.position = item.coordinate
marker.title = item.name!
marker.map = mapView
}
But, if I create a fake position with the current location and set the marker, it appears on the map:
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
}
Why?