Post Pic

iPhone SDK 3.0 - Playing with Map Kit

I started looking at the Map Kit API for developing a quick and dirty - Find where you parked your car - application.

There is no programming guide for Map Kit yet on the developer pages for Apple, So I decided to share some some of it here.

UPDATE: Follow the second part here
http://blog.objectgraph.com/index.php/2009/04/03/iphone-sdk-30-playing-with-map-kit-part-2/

I started looking at the Map Kit API for developing a quick and dirty - Find where you parked your car - application.

There is no programming guide for Map Kit yet on the developer pages for Apple, So I decided to share some some of it here.

The main class that supports a Map is called

MKMapView

You need to include the header

MapKit/MapKit.h

Also dont forget to add a reference to the Framework MapKit.Framework

The code is relatively simple. Here are the steps

  • Create a simple project - I chose utility application - Name it whatever you want
  • Go to MainViewController.h
  • Include the header MapKit/MapKit.h

Here is a screenshot of the code

As you can see i just created a reference to MKMapView

Now go to MainViewController.m

and just initialize the view and add it as a subview to the MainViewController’s view.

Thats it, You get a scrollable Map

By adding a few more parameters,

mapView.showsUserLocation=TRUE;
mapView.mapType=MKMapTypeHybrid;

You will see similar to below. User’s location on simulator looks like Apple’s HQ

Next time i will explore how to create points on the map.

Here is a reference to MKMapView class.

http://developer.apple.com/iphone/prerelease/library/documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html

Related posts:

  1. iPhone SDK 3.0 - Playing with Map Kit - Part 3 This is the 3 part of me Playing with Map...
  2. iPhone SDK 3.0 - Playing with Map Kit - Part 2 This is the second part of "Playing with Map Kit"...
  3. iPhone Development and a sample Objective C Program Kiichi and myself are learning how to program in Objective...
  4. iPhone Dictionary Just finished learning about the viewport metatag and implemeted this...
  5. Compiling Objective-C using only Command Line My newest love is TextMate, the ultimate Mac OSX text...

Related posts brought to you by Yet Another Related Posts Plugin.

18 Responses

04.02.09

Hi, have you been able to put annotations on the map

04.02.09

@Scoob

I am working on it. I will post an update to this blog later today

04.02.09

Hi, How can we put annotations on custom locations?
I mean the location where we want the annotation should fall?

04.02.09

Simpler way to get just the map showing up:

To simply get just the map showing up on the iPhone, create a new iPhone project using any template of your choice.

In the Frameworks folder, add the MapKit.Framework. This is a very important step and the one most likely to overlook.

Go to the NIB file where you want your map to show up. In Interface Builder, drag a MapView object from the Library (under Data Views). Size the MapView object appropriately.

Back in XCode, “Build and Run,” and you will see the map in the iPhone simulator.

04.02.09

[...] iPhone SDK 3.0 - Playing with Map Kit iPhone SDK 3.0 - Playing with Map Kit - Part 2 [...]

[...] Kit Article Check out a series of ObjectGraph’s blog entries: Map Kit API Part 1 iPhone SDK 3.0 - Playing with Map Kit - ObjectGraph Blog Map Kit API Part 2 iPhone SDK 3.0 - Playing with Map Kit - Part 2 - ObjectGraph Blog Map Kit API [...]

04.02.09

Nice walkthrough, although I have a problem when I am trying out your code. It gives me an error like this :

Line Location Tool:0: “.objc_class_name_MKMapView”, referenced from:

Do you have any idea what this means? Which SDK did you use btw? I am using v 3.0 as I intend to embed a map in another applications.

04.02.09

It turns out the system couldn’t find the MapKit framework so I had to import it. All good.

Hi ,

Thanks for the post which u made , but i am facing the following reference error , it would be greatly appreciable if any one can find the solution for these kind of errors .

Thanks in advance.

.obc_class_name_MKMapView, referenced from :
literal-pointer@_objc@_cls_refs@

04.02.09

I don’t have MapView in Library how to add it
thanks for nice post.

04.02.09

hi, i have downloaded .zip file and opened the project but i am getting following error:
error: There is no SDK with specified name or path ‘Unknown Path’
pls. help me out.

thanks

04.02.09

@kapil and jain: You will need the latest iPhone SDK (beta 5)

04.02.09

Is it possible to place pins on the map? I’ve looked around, but haven’t seen a good tutorial on how to do this. Any help would be greatly appreciated.

04.02.09

Hi ,Its nice tut..

Can you tell me Where can get MKReverseGeoCoder classes? plz

04.02.09

Hi, can you tell me if an internet connection is needed for use this Framework?

Thanks!

04.02.09

Hi Juan, Yes you will need internet connection to make the maps work. It basically uses google map api servers to render the onscreen map

04.02.09

Leave Your Response

* Name, Email, Comment are Required