Tutorial by Examples

Swift let mapView = MKMapView(frame: CGRect(x: 0, y: 0, width: 320, height: 500)) It's recommended to store the mapView as a property of the containing ViewController since you might want to access it in more complex implementations. Objective C self.map = [[MKMapView alloc]initWithFrame:CGRec...
There are 5 different types (MKMapType), MKMapView can display. iPhone OS 3 .standard Displays a street map that shows the position of all roads and some road names. Swift 2 mapView.mapType = .Standard Swift 3 mapView.mapType = .standard Objective-C _mapView.mapType = MKMapTypeStandard;...
For setting some zoom level, let say we want to zoom user's location with user location as center and 2km of area as radius. Then, we use following code MKUserLocation *userLocation = _mapView.userLocation; MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance (userLocation.location.coord...
MKLocalSearch allows users to search for location using natural language strings like "gym". Once the search get completed, the class returns a list of locations within a specified region that match the search string. Search results are in form of MKMapItem within MKLocalSearchResponse ob...
In some cases, you might not want to use the default maps, Apple provides. You can add an overlay to your mapView that contains custom tiles for example from OpenStreetMap. Let's assume, self.mapView is your MKMapView that you have already added to your ViewController. At first, your ViewControll...
This will show the user location on the map Objective-C [self.map setShowsUserLocation:YES]; Swift self.map?.showsUserLocation = true This will track the user location on the map, updating regions according Objective-C [self.map setUserTrackingMode:MKUserTrackingModeFollow]; Swift s...
For annotating some point of interest on map, we use pin annotation. Now, start by creating annotation object first. MKPointAnnotation *pointAnnotation = [[MKPointAnnotation alloc] init]; Now provide coordinate to pointAnnotation,as CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake...
Step 1: In Xcode: File -> New -> File -> Resource -> GPX File -> Next -> Give the GPX file a name(It's Taipei in this example) -> Create Step 2: Edit the GPX file <?xml version="1.0"?> <gpx version="1.1" creator="Xcode"> <wpt ...
When you show a location to your users, you might want the MKMapView to display a coordinate at a zoom-level instead of setting a region to show. This functionality is not implemented by default, so you need to extend MKMapView with a methods that do the complex calculation from a coordinate and zoo...
Get All Annotation //following method returns all annotations object added on map NSArray *allAnnotations = mapView.annotations; Get Annotation View for (id<MKAnnotation> annotation in mapView.annotations) { MKAnnotationView* annotationView = [mapView viewForAnnotation:annotation];...
Swift: mapView.showAnnotations(mapView.annotations, animated: true) Objective-C: [mapView showAnnotations:mapView.annotations animated:YES]; Demo:

Page 1 of 1