MapQuest iOS SDK

Put an Annotation on the Map

iOS with Map and Marker
@import Mapbox;
@import MapQuestMaps;

@interface ViewController() <MGLMapViewDelegate>

@property (nonatomic, weak) IBOutlet MQMapView *mapView;

@end

@implementation ViewController
 
- (void)addAnnotation
{
    //create annotation, add it to the map, then center the map on it using
    //setCenterCoordinate - allows you to customize the zoomlevel
    MGLPointAnnotation *mapQuestHQ = [[MGLPointAnnotation alloc] init];
    mapQuestHQ.coordinate = CLLocationCoordinate2DMake(39.750307, -104.999472);
    mapQuestHQ.title = @"MapQuest";
    mapQuestHQ.subtitle = @"Welcome to Denver!";

    [self.mapView addAnnotation:mapQuestHQ];
    [self.mapView setCenterCoordinate:mapQuestHQ.coordinate zoomLevel:10 animated:YES];
}

- (void)mapViewDidFinishLoadingMap:(MGLMapView *)mapView {
    [self addAnnotation];
}
@end
import MapQuestMaps
import Mapbox

class ViewController: UIViewController, MGLMapViewDelegate, UIActionSheetDelegate {

    @IBOutlet fileprivate weak var mapView: MQMapView?
    fileprivate func addAnnotation() {
        //create annotation, add it to the map, then center the map on it using
        //setCenterCoordinate - allows you to customize the zoomlevel
        let  mapQuestHQ = MGLPointAnnotation()
        mapQuestHQ.coordinate = CLLocationCoordinate2D(latitude: 39.750307, longitude: -104.999472)
        mapQuestHQ.title = "MapQuest"
        mapQuestHQ.subtitle = "Welcome to Denver!"

        mapView?.addAnnotation(mapQuestHQ)
        mapView?.setCenter(mapQuestHQ.coordinate, zoomLevel: 12, animated: false)
    }

    func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
        addAnnotation()
    }?.mapType = .satellite
    }
}

Responding to Annotation Events

The MapQuest iOS SDK provides a delegate for capturing when a user taps on an annotation. First, implement func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) and return true to let the SDK know that you want to display a callout view for the annotation. The SDK will show a simple callout view with title and subtitle of the annotation.

iOS with Annotation callout

- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id)annotation
{
    return YES;
}

    func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
        return true
    }

Custom Callout View

You can override the method func mapView(_ mapView: MGLMapView, calloutViewFor annotation: MGLAnnotation) -> MGLCalloutView? and return a custom view to be shown as callout view.