MapQuest Maps iOS SDK

Points of Interest

POI Selected

Mapquest Map styles often will show a point-of-interest (POI) on the map. You may want to be able to allow the user to click on the POI and do something with that - for example show information about that POI, navigate to the POI, or just show a bubble annotation.

@import Mapbox;
@import MapQuestMaps;
@import MQCore;

@interface ViewController() <MGLMapViewDelegate, MQMapViewPOIDelegate>
@property (nonatomic, weak) IBOutlet MQMapView *mapView;
@end

@implementation ViewController
//set delegates in Interface Builder or in code
-(void)viewDidLoad {
    self.mapView.delegate = self;
    self.mapView.poiDelegate = self;
}    

#pragma mark - MQMapViewPOIDelegate methods
- (void)mapView:(nonnull MGLMapView *)mapView didTapOnPOI:(MQNamedPlace *)poi {
   //handle tap on Point Of Interest in the delegate method
         [self.detailView updatePOIDetailsWithPOI:poi];
}
@end
import MapQuestMaps
import Mapbox
import MQCore

class ViewController: UIViewController, MGLMapViewDelegate, MQMapViewPOIDelegate {

    @IBOutlet fileprivate weak var mapView: MQMapView?

    //set delegates in Interface Builder or in code
    override func viewDidLoad() {
      mapView?.poiDelegate = self    
      mapView?.delegate = self    
    }

    //MARK: - MQMapViewPOIDelegate
    func mapView(_ mapView: MGLMapView, didTapOnPOI poi: MQNamedPlace!) {
      //handle tap on Point Of Interest in the delegate method
    }
}

Show an info panel when POI is touched

Create a custom view called POIDetailsView for showing details about the POI

#import <UIKit/UIKit.h>
@class MQNamedPlace;

@protocol POIDetailsViewDelegate <NSObject>
- (void)toggleDetailView;
@end

@interface POIDetailsView : UIView
@property (nonatomic, weak) IBOutlet id<POIDetailsViewDelegate> delegate;
- (void)updatePOIDetailsWithPOI:(MQNamedPlace *)poi;
@end

#import "POIDetailsView.h"
#import <MQCore/MQCore.h>

@interface POIDetailsView ()
@property(nonatomic, weak) IBOutlet UILabel *name;
@property(nonatomic, weak) IBOutlet UILabel *address;
@property(nonatomic, weak) IBOutlet UILabel *address2;
@end

@implementation POIDetailsView
- (IBAction)close:(id)sender {
    if([self.delegate respondsToSelector:@selector(toggleDetailView)]) {
        [self.delegate toggleDetailView];
    }
}
- (void)updatePOIDetailsWithPOI:(MQNamedPlace *)poi {
    self.name.text = poi.name;
    self.address.text = poi.geoAddress.street;
    self.address2.text = [NSString stringWithFormat:@"%@, %@-%@",poi.geoAddress.city, poi.geoAddress.state, poi.geoAddress.zip]; ;
}
@end
import Foundation
import UIKit
import MQCore

protocol POIDetailsViewDelegate {
    func toggleDetailView()
}

class POIDetailsView: UIView {
    var delegate : Any?
    @IBOutlet fileprivate var name:UILabel?
    @IBOutlet fileprivate var address:UILabel?
    @IBOutlet fileprivate var address2:UILabel?
    
    @IBAction func close(sender:Any) {
        if let delegate = delegate as? POIDetailsViewDelegate {
            delegate.toggleDetailView()
        }
    }
    
    func updatePOIDetails(_ poi:MQNamedPlace) {
        name?.text = (poi.name != nil) ? poi.name : ""
        address?.text = (poi.geoAddress?.street != nil) ? poi.geoAddress?.street:""        
        var address2String = ""
        if let city = poi.geoAddress?.city {
             address2String += city + ", "
        }
        if  let state = poi.geoAddress?.state {
            address2String += state
        }
        if let zip = poi.geoAddress?.zip {
            address2String += "-" + zip
        }
        
        address2?.text = address2String
    }
}

Capture the event when user taps in a POI and show details using POIDetailsView

#pragma mark - MQMapViewPOIDelegate methods
- (void)mapView:(nonnull MGLMapView *)mapView didTapOnPOI:(MQNamedPlace *)poi {
    [self.detailView updatePOIDetailsWithPOI:poi];
    [self toggleDetailView];
}
//MARK: - MQMapViewPOIDelegate
func mapView(_ mapView: MGLMapView, didTapOnPOI poi: MQNamedPlace!) {
    poiDetailsView?.updatePOIDetails(poi)
    toggleDetailView()
}