Skip to Content

Let’s start with a simple app to begin with. We’ll use the mapkit and show where we are on the map using the iphones internal GPS and map functionality. In a later stage we’ll connect to SAP and start reading some data and displaying it as well.

Step 1:

We’ll start with a single view application,

Screen Shot 2012-12-27 at 6.36.44 PM.png

click Next and give your Project a name,

Screen Shot 2012-12-27 at 6.38.18 PM.png

be sure to select ‘Use Storyboards’ and ‘Automatic Reference Counting’.

Step 2:

To make life simple we’ll be running our app on the iPhone. Select iPhone in the Devices dropdown in the iOS application target window.

Screen Shot 2012-12-27 at 6.41.35 PM.png

Step: 3 – Storyboards

Now lets get started with the storyboard.

Screen Shot 2012-12-27 at 6.45.07 PM.png

In the objects window drag a new Navigation view onto the storyboard and delete the tableview that comes with it. Create a new view controller to put our maps in. File->New->File and select Objective-C class. Lets call the class mapViewController. We’ll connect this to the new View that we will create in the Storyboard.

In order to create the new view in the Storyboard, click and drag a view onto the Storyboard from the objects window. Next, drag a MapView onto the view.

The Storyboard should look like this:

Screen Shot 2012-12-27 at 8.50.01 PM.png

Assign the newly created custom class to the view.

Screen Shot 2012-12-27 at 7.07.06 PM.png

Set the Map to show user location,

Screen Shot 2012-12-27 at 7.11.06 PM.png

Click on the Editor in the menu and CTRL click and drag the Map into the class to connect the Outlet. Then import the Mapkit.h file and add the appdelegate.  The new mapViewController.h file should look like this.

Screen Shot 2012-12-27 at 7.14.33 PM.png

Add the MapKit  and the CoreLocation frameworks to the Project.

Screen Shot 2012-12-27 at 7.15.36 PM.png

The mapViewController.m should look like this,

//

//  mapViewController.m

//  sapMaps

//

//  Created by stu on 12/27/12.

//  Copyright (c) 2012 stu. All rights reserved.

//

#import <MapKit/MapKit.h>

#import <CoreLocation/CoreLocation.h>

#import “mapViewController.h”

@interface mapViewController ()

@end

@implementation mapViewController

@synthesize _mapView;

– (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}

– (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

     _mapView.delegate = self;

}

– (void) viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:NO animated:animated];

    _mapView.showsUserLocation = YES;

   

   

   

   

}

– (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation;

{

    CLLocationCoordinate2D zoomLocation;

    zoomLocation.latitude = _mapView.userLocation.location.coordinate.latitude;

    zoomLocation.longitude= _mapView.userLocation.location.coordinate.longitude;

    // 2

    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);

    // 3

    MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];

    // 4

    [_mapView setRegion:adjustedRegion animated:YES];

   

   

    

}

– (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

Step 4:

Go to the simulator and select the iPhone 6.0 simulator and run your project.

The simulator will popup and the map will display your location.

You can also attach your iPhone and run the application on your iPhone.

Thats it for the first steps in building an application. Contact me if you would like the source code. In the next post we will look at the code in detail and see what makes the app work and how we can change it.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply