Swift Map Annotations and Plist - Help

Joined
Dec 17, 2009
Messages
16
Reaction score
0
Points
1
Location
England
Your Mac's Specs
MBP 15", MBP 13", MBA 11" iPad 1 64GB & 32GB, iPad 2 32GB, iPhone 5 32Gb & 64, iPhone 4 32Gb
Hi all

Im stuck on trying to work with Swift

I want to load my map annotations from an external plist file or similar.

Then import that plist into an array and then read the array.

Ive tried multiple bits of code and nothing is working.

So far my app gains the users location and then continually updates ther location.

Any help appreciated.

Thanks
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I don't know much about Swift but there are a few here that might be willing to use their knowledge. In the meantime, can you provide some code so that we have context?
 
OP
M
Joined
Dec 17, 2009
Messages
16
Reaction score
0
Points
1
Location
England
Your Mac's Specs
MBP 15", MBP 13", MBA 11" iPad 1 64GB & 32GB, iPad 2 32GB, iPhone 5 32Gb & 64, iPhone 4 32Gb
Hi,

So far I have a plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>name</key>
<string>London Eye</string>
<key>location</key>
<string>{51.503324,-0.119543}</string>
</dict>
<dict>
<key>name</key>
<string>Big Ben</string>
<key>location</key>
<string>{51.500729,-0.124625}</string>
</dict>
</array>
</plist>

var LEAnnotation = MKPointAnnotation ()
LEAnnotation.coordinate = LondonEye
LEAnnotation.title = "London Eye"
LEAnnotation.subtitle = "You are looking at the London Eye"

// Add the annotation to the MapView
myMapView.addAnnotation(LEAnnotation)

Is how I'm adding annotations currently.

Now i want to use the data from the plist to add the annotations

Is it possible? Using Swift and Xcode 6
 
OP
M
Joined
Dec 17, 2009
Messages
16
Reaction score
0
Points
1
Location
England
Your Mac's Specs
MBP 15", MBP 13", MBA 11" iPad 1 64GB & 32GB, iPad 2 32GB, iPhone 5 32Gb & 64, iPhone 4 32Gb
I have now got this,

func addAttractionPins() {
let filePath = NSBundle.mainBundle().pathForResource("LondonPlaces", ofType: "plist")
let attractions = NSArray(contentsOfFile: filePath!)
for attraction in attractions! {
let point = CGPointFromString(attraction["location"] as String)
let coordinate = CLLocationCoordinate2DMake(CLLocationDegrees(point.x), CLLocationDegrees(point.y))
let title = attraction["name"] as String
let annotation = AttractionAnnotation(coordinate: coordinate, title: title)
myMapView.addannotation(annotation)
}
}

With the help of an online tutorial, I'm now getting an error on line let annotation...
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top