I have an array of latitudes and longitudes along with other stuffs and I want to create annotations in Map view. I’m using MapKit.
When ever the user clicks the annotation callout I’m going to present another controller. I’m not able to find the index of the array element that was used to create that particular annotation.
Below is my code.
I have a Int variable
var annotationIndex = 0
This is where I add annotations
func addAnnotation(latitude: Double, longitude: Double, title: String, subTitle: String?) {
if (latitude >= -90 && latitude <= 90) && (longitude >= -180 && longitude <= 180) {
let location = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location, span: span)
mapView.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = title
annotation.subtitle = subTitle
mapView.addAnnotation(annotation)
}
}
This is an MKMapViewDelegate method to customize annotation
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!
{
if !(annotation is MKPointAnnotation)
{
return nil
}
let reuseId = "test"
var aView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
aView.canShowCallout = true
let btn = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
btn.addTarget(self, action: "btnDisclosureAction:", forControlEvents: UIControlEvents.TouchUpInside)
btn.tag = annotationIndex
annotationIndex++
aView.rightCalloutAccessoryView = btn
return aView
}
This is the rightCalloutAccessoryView Button Action
func btnDisclosureAction(sender: UIButton) {
println(sender.tag)
}
Right now I'm just printing the callout diusclosure button tag which I try setting it using an annotationIndex variable.
Since the annotationView is reused I cannot get the exact index value.Is there a better way to do it?
Subclass MKPointAnnotation to have index value.
class
Annotation : MKPointAnnotation {
var index = 0
}
And set index when annotation is created.
let annotation = Annotation()
:
annotation.subtitle = subTitle
annotation.index = annotationIndex++
Pass annotation's index to btn
btn.addTarget(self, action: "btnDisclosureAction:", forControlEvents: UIControlEvents.TouchUpInside)
btn.tag = ( annotation as! Annotation ).index
EDIT:
So your viewForAnnotation will be
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!
{
if !(annotation is Annotation)
{
return nil
}
let reuseId = "test"
var aView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
aView.canShowCallout = true
let btn = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
btn.addTarget(self, action: "btnDisclosureAction:", forControlEvents: UIControlEvents.TouchUpInside)
btn.tag = ( annotation as! Annotation ).index
aView.rightCalloutAccessoryView = btn
return aView
}
Specify indexselected as class variable and initilise it with -1 in viewDidLoad method ,like
override func viewDidLoad() {
super.viewDidLoad()
indexselected = -1
}
You can get your annotation index while user tap on annotation, and didSelectAnnotationView method get called automatically.
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
var selectedAnnotation : MKPointAnnotation = MKPointAnnotation()
selectedAnnotation = view.annotation as! MKPointAnnotation
for var i = 0; i<yourlist.count ; i++ {
let strtitle : String = yourlist.objectAtIndex(i).title as! String
if selectedAnnotation.title == strtitle {
indexselected=i
break
}
}
}
We can get annotation index by comparing title on annotation and title from your array, and save the index from array. On selection of button method you can use that index.
func btnDisclosureAction(sender: UIButton) {
println(indexselected)
}
Hope this help you.
Related
I'm showing an array of annotations in a map view and need to have the corresponding title and subtitle with each annotation. My current code only gets me the 1st title/subtitle on all of the annotations.
func multiPoint() {
var coordinateArray: [CLLocationCoordinate2D] = []
if receivedArrayOfLats.count == receivedArrayOfLongs.count {
for i in 0 ..< receivedArrayOfLats.count {
let eventLocation = CLLocationCoordinate2DMake(receivedArrayOfLats[i], receivedArrayOfLongs[i])
coordinateArray.append(eventLocation)
}
}
for events in coordinateArray {
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: events.latitude, longitude: events.longitude)
annotation.title = receivedAgencyEventSubTypeCode
annotation.subtitle = receivedAgencyId
multiEventMap?.addAnnotation(annotation)
}
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let reuseIdentifier = "annotationView"
var view = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)
if #available(iOS 11.0, *) {
if view == nil {
view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
}
view?.displayPriority = .required
} else {
if view == nil {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
}
}
view?.annotation = annotation
view?.canShowCallout = true
return view
}
No big surprise. You loop making annotations, and you are saying
annotation.title = receivedAgencyEventSubTypeCode
annotation.subtitle = receivedAgencyId
for every annotation thru the loop. The annotation is different each time. But the values on the right side never change so all the titles and subtitles are the same.
Can any one help me to add different button action to the second annotation /pin (annotation2), Now the button do the same work in the two annotation pins how to do different work to each other . I'am using Swift3 in my project and this is my code . thanks
This is my code.
import UIKit
import MapKit
import CoreLocation
class MyAnnotation: MKPointAnnotation {
var uniqueId: Int!
}
class LocationViewController: UIViewController , MKMapViewDelegate , CLLocationManagerDelegate{
#IBOutlet weak var map: MKMapView!{
didSet{
map.delegate = self
}
}
#IBOutlet weak var locationInfo: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
let locations = CLLocationCoordinate2DMake(33.314627, 44.303500)
let location2 = CLLocationCoordinate2DMake(33.312149, 44.3024567)
let span = MKCoordinateSpanMake(0.02, 0.02)
let span2 = MKCoordinateSpanMake(0.02, 0.02)
let region = MKCoordinateRegionMake(locations, span)
let region2 = MKCoordinateRegionMake(location2, span2)
map.setRegion(region, animated: true)
map.setRegion(region2, animated: true)
let annotation = MyAnnotation()
//annotation.setCoordinate(location)
annotation.coordinate = locations
annotation.title = "Zaid Homes"
annotation.subtitle = "Hay aljameaa"
annotation.uniqueId = 1
map.addAnnotation(annotation)
let annotation2 = MyAnnotation()
//annotation.setCoordinate(location)
annotation2.coordinate = location2
annotation2.title = "Zaid "
annotation2.subtitle = "aljameaa"
annotation.uniqueId = 2
map.addAnnotation(annotation2)
//Showing the device location on the map
self.map.showsUserLocation = true;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var view = mapView.dequeueReusableAnnotationView(withIdentifier: "AnnotationView Id")
if view == nil{
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "AnnotationView Id")
view!.canShowCallout = true
} else {
view!.annotation = annotation
}
view?.leftCalloutAccessoryView = nil
view?.rightCalloutAccessoryView = UIButton(type: UIButtonType.detailDisclosure)
return view
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if (control as? UIButton)?.buttonType == UIButtonType.detailDisclosure {
mapView.deselectAnnotation(view.annotation, animated: false)
if let myAnnotation = view.annotation as? MyAnnotation {
if (myAnnotation.uniqueId == 1) {
performSegue(withIdentifier: "info", sender: view)
}
else {
performSegue(withIdentifier: "info2", sender: view)
}
}
}
}
}
The simplest way to know on which annotation you tap is using creating custom annotation class and adding annotation of it. So create one annotation class MyAnnotation child class of MKPointAnnotation and maintain one uniqueId with your multiple annotation.
class MyAnnotation: MKPointAnnotation {
var uniqueId: Int!
}
Now you need to add annotation of type MyAnnotation instead of MKPointAnnotation.
let annotation = MyAnnotation()
annotation.coordinate = locations
annotation.title = "Zaid Homes"
annotation.subtitle = "Hay aljameaa"
//Set uniqueId for annotation
annotation.uniqueId = 1
map.addAnnotation(annotation)
let annotation2 = MyAnnotation()
annotation2.coordinate = location2
annotation2.title = "Zaid "
annotation2.subtitle = "aljameaa"
//Set uniqueId for annotation
annotation2.uniqueId = 2
map.addAnnotation(annotation2)
Now check this uniqueId in calloutAccessoryControlTapped method on which annotation you tapped.
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if (control as? UIButton)?.buttonType == UIButtonType.detailDisclosure {
mapView.deselectAnnotation(view.annotation, animated: false)
if let myAnnotation = view.annotation as? MyAnnotation {
if (myAnnotation.uniqueId == 1) {
performSegue(withIdentifier: "info1", sender: view)
}
else {
performSegue(withIdentifier: "info2", sender: view)
}
}
}
}
you can do this by creating two subClass of MKPointAnnotation and then in the delegate's method you can do this :
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if view is subClass1 {
// do action for subclass 1
}
else if view is subClass2 {
// do action for subClass 2
}
}
Please let me know if this resolve your problem.
Update
you can make the implementation of you delegate more simpler like this exemple :
class ClassA:MKPointAnnotation{
func doActionWhenCalloutTapped(){
//do some action
}
}
class ClassB:ClassA{
override func doActionWhenCalloutTapped(){
//do some actions for annotation of type B
}
}
class ClassC:ClassA{
override func doActionWhenCalloutTapped(){
//do some actions for annotation of type C
}
}
func viewDidLoad(){
super.viewDidLoad()
let annotation = ClassB()
//annotation.setCoordinate(location)
annotation.coordinate = locations
annotation.title = "Zaid Homes"
annotation.subtitle = "Hay aljameaa"
map.addAnnotation(annotation)
let annotation2 = ClassC
//annotation.setCoordinate(location)
annotation2.coordinate = location2
annotation2.title = "Zaid "
annotation2.subtitle = "aljameaa"
map.addAnnotation(annotation2)
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
(view.annotation as! ClassA).doActionWhenCalloutTapped()
}
The below code works and gives me a draggable annotation view. However, I've noticed that the annotation view is not draggable from the very beginning on, but rather only after the finger has rested for a short moment on the annotation view. When directly going into a drag movement the dragging doesn't affect the annotation view but instead pans the map. It certainly doesn't feel like drag'n'drop. Both on the device and in the simulator.
ViewController (Delegate of the MapView)
override func viewDidLoad() {
/// ...
let gestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(addPin))
mapView.addGestureRecognizer(gestureRecognizer)
}
func addPin(gestureRecognizer: UIGestureRecognizer) {
if gestureRecognizer.state != UIGestureRecognizerState.Began {
return
}
for annotation in mapView.annotations {
mapView.removeAnnotation(annotation)
}
let touchLocationInView = gestureRecognizer.locationInView(mapView)
let coordinate = mapView.convertPoint(touchLocationInView, toCoordinateFromView: mapView)
let annotation = DragAnnotation(coordinate: coordinate, title: "draggable", subtitle: "")
mapView.addAnnotation(annotation)
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isKindOfClass(DragAnnotation) {
let reuseIdentifier = "DragAnnotationIdentifier"
var annotationView: MKAnnotationView!
if let dequeued = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseIdentifier) {
annotationView = dequeued
} else {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
}
annotationView.annotation = annotation
annotationView.image = UIImage(named: "bluedisk2")
annotationView.canShowCallout = false
annotationView.draggable = true
return annotationView
}
return nil
}
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, didChangeDragState newState: MKAnnotationViewDragState, fromOldState oldState: MKAnnotationViewDragState) {
switch (newState) {
case .Starting:
view.dragState = .Dragging
case .Ending, .Canceling:
view.dragState = .None
default: break
}
}
DragAnnotation
import UIKit
import MapKit
class DragAnnotation : NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D {
didSet {
print(coordinate)
}
}
var title: String?
var subtitle: String?
init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
}
}
I don't think you can change the draggable delay, but you could disable it and add your own drag gesture that has no delay (or a shorter delay):
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation { return nil }
var view = mapView.dequeueReusableAnnotationViewWithIdentifier("Foo")
if view == nil {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "Foo")
view?.draggable = false
let drag = UILongPressGestureRecognizer(target: self, action: #selector(handleDrag(_:)))
drag.minimumPressDuration = 0 // set this to whatever you want
drag.allowableMovement = .max
view?.addGestureRecognizer(drag)
} else {
view?.annotation = annotation
}
return view
}
private var startLocation = CGPointZero
func handleDrag(gesture: UILongPressGestureRecognizer) {
let location = gesture.locationInView(mapView)
if gesture.state == .Began {
startLocation = location
} else if gesture.state == .Changed {
gesture.view?.transform = CGAffineTransformMakeTranslation(location.x - startLocation.x, location.y - startLocation.y)
} else if gesture.state == .Ended || gesture.state == .Cancelled {
let annotationView = gesture.view as! MKAnnotationView
let annotation = annotationView.annotation as! DragAnnotation
let translate = CGPoint(x: location.x - startLocation.x, y: location.y - startLocation.y)
let originalLocation = mapView.convertCoordinate(annotation.coordinate, toPointToView: mapView)
let updatedLocation = CGPoint(x: originalLocation.x + translate.x, y: originalLocation.y + translate.y)
annotationView.transform = CGAffineTransformIdentity
annotation.coordinate = mapView.convertPoint(updatedLocation, toCoordinateFromView: mapView)
}
}
By the way, if you're going to change the coordinate of an annotation, you will want to add dynamic keyword to your custom class coordinate declaration so that the appropriate KVO notifications will be issued.
class DragAnnotation: NSObject, MKAnnotation {
dynamic var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?
init(coordinate: CLLocationCoordinate2D, title: String? = nil, subtitle: String? = nil) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
super.init()
}
}
Note, in this example, I set the delay to zero. That means that if you tap on the annotation (the typical UI for "show the callout"), this may prevent that from working correctly. It will treat this as a very short drag. This is why the standard UI requires a delay in the long press before dragging.
So, for this reason, I personally would hesitate to override this behavior shown above because it will be different then standard map behavior that the end user is familiar with. If your map behaves differently than any other maps on the user's device, this could be a source of frustration.
I would have to add a button for my particular point of entry , where I click to open the Maps app already passing the coordinates of the selected point. Does anyone know how to do? my code is this. The image is what I would have.
My code:
import Foundation
import UIKit
import MapKit
import CoreLocation
class PuntiVenditaController: UIViewController, MKMapViewDelegate {
#IBOutlet weak var menuButton:UIBarButtonItem!
#IBOutlet weak var mapView: MKMapView!
let regionRadius: CLLocationDistance = 1000
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
if revealViewController() != nil {
menuButton.target = revealViewController()
menuButton.action = "revealToggle:"
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
let location = CLLocationCoordinate2D(latitude: 41.225891, longitude: 16.291489)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location, span: span)
mapView.setRegion(region, animated: true)
mapView.showsPointsOfInterest = false
mapView.showsUserLocation = true
displayMarkers()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func centerMapOnLocation(location: CLLocation) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
regionRadius * 2.0, regionRadius * 2.0)
mapView.setRegion(coordinateRegion, animated: true)
}
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView{
println(view.annotation.title) // annotation's title
println(view.annotation.subtitle) // annotation's subttitle
//Perform a segue here to navigate to another viewcontroller
// On tapping the disclosure button you will get here
}
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
println("viewForannotation")
if annotation is MKUserLocation {
//return nil
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
//println("Pinview was nil")
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
}
var button = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton // button with info sign in it
pinView?.rightCalloutAccessoryView = button
return pinView
}
func displayMarkers() -> Void
{
let annotationView = MKAnnotationView()
// Adding button here wont do anything so remove these two lines
let detailButton: UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
annotationView.rightCalloutAccessoryView = detailButton
// For adding button we have to use a method named as viewForAnnotation
let annotation = MKPointAnnotation()
let name = "Title"
let latitude = 41.225891
let longitude = 16.291489
annotation.title = name
var markerLatitude: Double = latitude
var markerLongitude: Double = longitude
let location = CLLocationCoordinate2D(latitude: markerLatitude, longitude: markerLongitude)
annotation.coordinate = location
annotation.subtitle = "Subtitle"
mapView.addAnnotation(annotation)
}
}
You can open an URL to open the Maps App at a specific point/address:
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
But I don't think, you can design a custom marker within the Maps App
I just wrote few lines of code and got stuck trying add a detail button to my annotation point, I don't know how. Does anyone know how to do that? The image below shows what I want to achieve. Thanks!
http://i.stack.imgur.com/kK1Ox.jpg
Im trying to get the big i in the circle in my annotation.
Right now I just have an annotation with a title and a subtitle, which looks like below.
http://imgur.com/L3VMe5l.png
Also, if you know, when a user clicks on the i in the circle, how do i bring them to a new segue?
Thanks for your help.
import UIKit
import MapKit
class PropertyMasterViewConroller: UIViewController, MKMapViewDelegate {
#IBOutlet weak var nMapView: MKMapView!
#IBOutlet weak var testButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
//Location of Boston College
let initLocation = CLLocationCoordinate2D(
latitude: 42.335992,
longitude: -71.167333
)
//Span of the Map
let span = MKCoordinateSpanMake(0.1, 0.1)
let region = MKCoordinateRegion(center: initLocation, span: span)
nMapView.setRegion(region, animated: true)
addAnnotations()
testButton.setTitle("Test Button", forState: .Normal)
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"nav.png"), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
}
// When user taps on the disclosure button you can perform a segue to navigate to another view controller
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView{
println(view.annotation.title) // annotation's title
println(view.annotation.subtitle) // annotation's subttitle
//Perform a segue here to navigate to another viewcontroller
// On tapping the disclosure button you will get here
}
}
// Here we add disclosure button inside annotation window
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
println("viewForannotation")
if annotation is MKUserLocation {
//return nil
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
//println("Pinview was nil")
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
}
var button = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as UIButton // button with info sign in it
pinView?.rightCalloutAccessoryView = button
return pinView
}
func addAnnotations() -> Void {
let annotationView = MKAnnotationView()
let detailButton: UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as UIButton
annotationView.rightCalloutAccessoryView = detailButton
//1070 Beacon
let annotation = MKPointAnnotation()
annotation.setCoordinate(CLLocationCoordinate2D (latitude: 42.345532,longitude: -71.109526))
annotation.title = "1070 Beacon Street"
annotation.subtitle = "Brookline, MA 02446"
nMapView.addAnnotation(annotation)
//1070 Beacon
let location_18 = MKPointAnnotation()
location_18.setCoordinate(CLLocationCoordinate2D (latitude: 42.347236,longitude: -71.15000))
location_18.title = "18 Shepard Street"
location_18.subtitle = "Brighton, MA 02135"
nMapView.addAnnotation(location_18)
//1070 Beacon
let location_26 = MKPointAnnotation()
location_26.setCoordinate(CLLocationCoordinate2D (latitude: 42.358663,longitude: -71.146024))
location_26.title = "26 Lincoln Street"
location_26.subtitle = "Brighton, MA 02135"
nMapView.addAnnotation(location_26)
//1070 Beacon
let location_1280 = MKPointAnnotation()
location_1280.setCoordinate(CLLocationCoordinate2D (latitude: 42.363639,longitude: -71.139366))
location_1280.title = "1280 Soldiers Field Road"
location_1280.subtitle = "Brighton, MA 02135"
nMapView.addAnnotation(location_1280)
//1070 Beacon
let location_59 = MKPointAnnotation()
location_59.setCoordinate(CLLocationCoordinate2D (latitude: 42.363147,longitude: -71.201493))
location_59.title = "59-85 Chapel Street"
location_59.subtitle = "Newton, MA 02458"
nMapView.addAnnotation(location_59)
//1070 Beacon
let location_1 = MKPointAnnotation()
location_1.setCoordinate(CLLocationCoordinate2D (latitude: 42.309260,longitude: -71.134556))
location_1.title = "1 Newton Place"
location_1.subtitle = "Newton, MA 02458"
nMapView.addAnnotation(location_1)
}
}
I do not have access to your second image url but I assume you are looking something as follows. If not, leave comment below.
func mapView(mapView: MKMapView!, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == annotationView.rightCalloutAccessoryView {
performSegueWithIdentifier("Detail", sender: self)
}
}
You could also refer to the following examples:
MKPointAnnotations touch event in swift
MapKit in Swift, Part 2
http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial