
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.
Related posts:
- iPhone SDK 3.0 – Playing with Map Kit – Part 3 This is the 3 part of me Playing with Map...
- iPhone SDK 3.0 – Playing with Map Kit – Part 2 This is the second part of "Playing with Map Kit"...
- iPhone SDK 3.0 – Playing with Game Kit – Part 1 My first series of articles explaining how to use Game...
- iPhone Development and a sample Objective C Program Kiichi and myself are learning how to program in Objective...
- iPhone Dictionary Just finished learning about the viewport metatag and implemeted this...
Related posts brought to you by Yet Another Related Posts Plugin.

























49 Responses
Hi, have you been able to put annotations on the map
@Scoob
I am working on it. I will post an update to this blog later today
Hi, How can we put annotations on custom locations?
I mean the location where we want the annotation should fall?
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.
http://blog.objectgraph.com/index.php/2009/04/03/iphone-sdk-30-playing-with-map-kit-part-2/
[...] 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 [...]
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.
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@
I don’t have MapView in Library how to add it
thanks for nice post.
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
@kapil and jain: You will need the latest iPhone SDK (beta 5)
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.
Hi ,Its nice tut..
Can you tell me Where can get MKReverseGeoCoder classes? plz
Hi, can you tell me if an internet connection is needed for use this Framework?
Thanks!
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
@LakshmilKanth Try this:
http://discussions.apple.com/thread.jspa?threadID=1987699&tstart=0
[...] file into the folder with the rest of the frameworks. The only sample code I know of is here other than Session 118 of WWDC 2009 which very few people have access to. If anyone finds any more [...]
[...] I put my map-based projects on hold… until yesterday, that is, when I came across a 3-part tutorial that very clearly shows how all the pieces are put together. A simple “Dude, where’s [...]
To avoid getting this error “.obc_class_name_MKMapView, referenced from :
literal-pointer@_objc@_cls_refs@”, follow these steps ->
Add the MapKit framework to your Xcode project:
1. Click on Frameworks folder in the Groups & Files pane.
2. Project -> Add to Project
3. Macintosh HD -> Developer -> Platforms -> iPhoneSimulator.platform -> Developer -> SDKs ->iPhoneSimulator3.0.sdk ->System -> Library -> Frameworks -> MapKit.framework (select it, don’t go any lower)
May be a stupid question (I’m a beginner programmer), but when you say “add in a few more parameters” :
mapView.showsUserLocation=TRUE;
mapView.mapType=MKMapTypeHybrid;
Where in the code does this actually go? I have put it in the viewdidload method but don’t see the same as your screen prints (I’m still getting the standard map, not showing ‘Apple HQ’):
- (void)viewDidLoad
{
[super viewDidLoad];
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
mapView.showsUserLocation=TRUE;
mapView.mapType=MKMapTypeHybrid;
[self.view insertSubview:mapView atIndex:0];
}
I’m using the simulator, so would I expect to see what you have shown in your example screen shots in this tutorial?
Thank you!
@Steve,
An easier way would be to just add the mapview in interface builder. When i was writing these tutorials, i was not using IB.
Just drag and drop map view and then set the property to show users current location. Make a reference to it as an IBOutlet so you can control what do display on it.
[...] a search through Google I found a mapkit blog post a that provided a quick walkthrough and examples that will help [...]
[...] Check the tutorial. [...]
[...] this interesting tutorial in 3 parts for start with Map [...]
I didn’t see anyone respond to the question about where to find the MapKit framework. You mention “don’t forget to add a reference…”. For those of you who, like me, are new to XCode, that means you need to add a reference to MapKit in the “Frameworks” section of your project because by default MapKit is NOT in /System/Library/Frameworks because they’re not Mac OS X frameworks. You will find MapKit in /Developer/Platforms/iPhoneOS.Platform/Developer/SDKs//System/Library/Frameworks. What I did was drag the MapKit folder that I found in /Developer/Platforms/… into the “Frameworks” folder of my project.
Is there any way to display path(direction) for two location in built in Google maps of SDK 3.0 ? Thanks in Advance.
Thanks for your post…
How would you display your current path taken, if you are in a car or riding your bike…just like the built-in “Maps” application. So, basically constantly update your location and show that in the map. But on top of that, keep track or all the location you have “visited” to draw a path?
Thanks
I’m receiving an error: ‘mapView’ undeclared on this line: mapView=[[MKMapView alloc] initWithFrame:self.view.bounds];
How do I declare this?
Thanks!
Hi Im trying to do this, in the SDK 3.1 and im getting stuck in the “.obc_class_name_MKMapView, referenced from :
literal-pointer@_objc@_cls_refs@” error, i allready add the framework but im really getting stuck. Theres something i have to do?!
[...] I put my map-based projects on hold… until yesterday, that is, when I came across this easy-to-understand 3-part tutorial with sample code that very clearly shows how all the pieces are put together. A simple “Dude, where’s my [...]
[...] di Apple ha confermato ufficialmente l’interesse dell’azienda nell’estensione del framework MapKit, collegato a Compass e tutte le applicazioni che utilizzano la geo-localizzazione, sia su iPhone [...]
I’m very new to programming and I’m having trouble on the second part (MainViewController.m). What do you mean by “initialize and add it as a subview”? I’ve copied the code and I’m getting an error when I try to build and go.
Hi everyone,
I want to ask a question if anybody can help me in that, how i can highlight an area surrounded by a polygon using Maplkit?? or is there anyway of doing that?
regards,
Hassan Ali
Thanks gavi for the tutorial, but I would be helpful if you mentioned how we could add a framework to a project
.
Thanks @Vimal Goel for the hint about the map framework
How can i pull up a map on iPhone simulator and place a custom annotation on my current location.
Please help me out. Its for educational purpose.
Thanks,
A quick way to add MapKit.framework to your project: Control-click on Frameworks -> Add -> Existing Frameworks and choose the MapKit framework.
Thank you very much for your post. These 3 parts are exactly what I’m looking for. Great job.
In order to add the mapview to the uiview why do we need to use “insertSubView” method???
Can’t we use addSubview???
we’ll i found another way to add the mapview —
self.view = mapView //where self is a view controller and mapView is MapView;
[...] Playing with Map Kit – Slightly more detailed, 3-part, tutorial explaining how to create a “Where Did I Park?” style application. [...]
[...] iPhone SDK 3.0 – Playing with Map Kit – ObjectGraph Blog (tags: mapkit iphone iphone_dev) [...]
Nice Article, and its very simple to make too.
Thanks for sharing.
Hi, how do you create your own map for an iphone app. I am a new iphone developper and i have my map as a picture but I would like to add annotations and a key for the map too. So how do I do that with iphone SDK 3.0. This is not a Google map it is just like a sketch for a small location. Thank you.
What are the conditions for using these tools? I do mostly small custom iPhone apps. Am I allowed to use it in this case.
This is well written, easy to understand, but there are some links I’m not allowed to get into, are these links to the Apple’s SDK sites linking with the $99 version ones….
[...] You can find an excellent tutorial for getting you started with the MapKit Here [...]
[...] You can find an excellent tutorial for getting you started with the MapKit Here [...]
Hi,
I’m new to iphone development. I’m trying out your mapkit tutorial and it’s working pretty well for me. I was hoping you can point me in the right direction for something….I want to display anotations based on a location name and city. (without prior knowledge of the coordinates) is that possible?
Thanks in advance
This is good stuff, thank you for spending your time showing this. Just curios, can someone show how to place multiple push pins on the map…thanks!