Reputation: 43
Im creating a tagging app where users can tag Street Art to a map. I want users to be able to click on the pins (i) callout button and be taken to Apple Maps.
This function should allow that to happen however I get an error "instance member 'coordinate' can not be used on type 'art'" -
func openInMaps() {
let regionDistance:CLLocationDistance = 1000
let coordinates = art.coordinate
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates!, regionDistance, regionDistance)
let options = [
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
]
let placemark = MKPlacemark(coordinate: coordinates!, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = art.name
mapItem.openInMaps(launchOptions: options)
}
And this is my art class -
import Foundation
import FirebaseDatabase
import CoreLocation
class art {
let coordinate: CLLocationCoordinate2D!
var name: String!
var location: String!
var type: String!
var ref: FIRDatabaseReference?
init(snapshot: FIRDataSnapshot) {
let snapshotValue = snapshot.value as! [String: Any]
ref = snapshot.ref
name = snapshotValue["name"] as! String
location = snapshotValue["location"] as! String
coordinate = CLLocationCoordinate2D(latitude: snapshotValue["lat"] as! Double, longitude: snapshotValue["lng"] as! Double)
// type = snapshotValue["type"] as! String
}
}
Would be great for someone to point me in the right direction or tell me if what Im doing is wrong! thanks.
Upvotes: 1
Views: 24