I would like to create my own markers because I need to track extra information about them (for example, date added, marker ID)...
So I created another class, as follows:
class myMarker: GMSMarker {
var markerID: Int
var addedDate: NSDate
}
But I don't know what do to next... should I create an "init" method to populate my markerId and addedDate? or I should override the GMSMarker constructor (which is not "init") It can be
class myMarker: GMSMarker {
var markerID: Int
var addedDate: NSDate
var myMarker: GMSMarker
init(marID: Int, date: NSDate, GMSMarker: markerwithoutDateNorId){
self.markerID = marID
self.addedDate = date
self.myMarker = markerwithoutDateNorId
}
}
I really don't have an idea how to implement this. Maybe I don't even need to implement a constructor, but use the GMSMarker constructor (which I believe I inherited) and then use set methods to set marker ID and Date?
Or I could override GMSMarker constructor, to then use super(what-is-expecting-here) and then I would add the date and marker ID.
I really need to create my own type of marker, because I need to keep track of these things... for example, I would like, in a future, remove all markers older than 1 week for example... and if I don't keep track of markers date, that would me impossible.
Im really need to Swift and programming in general. I'd really appreciate your help :)
There is an another approach, GMSMarker has userData property which can accept AnyObject.
var info: Dictionary<String, AnyObject>?
info[“markerID”] = 0
info[“addedDate”] = NSDate()
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude:latitude, longitude:longitude)
marker.map = nil
marker.tracksInfoWindowChanges = false
marker.map = self.mapView
marker.userData = info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With