Create an App that will drop PushPins onto a map based on addresses that the user inputs.

Similar documents
Building Mapping Apps for ios With Swift

Stanford CS193p. Developing Applications for ios. Spring Stanford CS193p. Spring 2012

Covers ios 6. Bear Cahill. Includes 98 Techniques MANNING

Why Using Location and Map? iphone Application Programming L12: Location and Maps. Why Using Location and Map? Determine where you are

What s New in MapKit. App Frameworks #WWDC17. Fredrik Olsson

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011

A Mobile Mapping Application

ITP 342 Mobile App Dev. Locations and Maps

Index. btndrop function, 224, 226 btngetquote function, 246 btnpressed function, 28 btnquote method, 245. CallWeb method, 238, 240

InterfaceBuilder and user interfaces

Stanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Fall Stanford CS193p Fall 2010

Maps, locations & sensors in ios

Apple introduced MapKit with ios, maps were based on Google.

Mobile Development Lab 3

View Controllers CPRE 388

CS 47. Beginning iphone Application Development

Integrating Game Center into a BuzzTouch 1.5 app

Developing Applications for ios

iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5

Objectives. Submission. Register for an Apple account. Notes on Saving Projects. Xcode Shortcuts. CprE 388 Lab 1: Introduction to Xcode

View Controller Lifecycle

Developing Applications for ios

Apple Development Technology Workshops

ios Development - Xcode IDE

Core Animation. Building Animated UI s. Bill Dudney. Gala Factory Software LLC. Bill Dudney Core Animation: Building Animated UI s Slide 1

Building the App - Part 5 - Adding a Link

ITP 342 Mobile App Dev. Web View

Mobile Development - Lab 2

ios DeCal : Lecture 2 Structure of ios Applications: MVC and Auto Layout

OVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net

Assignment II: Foundation Calculator

Intro to Native ios Development. Dave Koziol Arbormoon Software, Inc.

Developing Applications for ios

Contents. iphone Training. Industry Trainers. Classroom Training Online Training ON-DEMAND Training. Read what you need

Why Model-View-Controller?

CS193E Lecture 7. Document-based Applications NSTableView Key-Value Coding

CS193p Spring 2010 Wednesday, May 26, 2010

Advanced ios. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 20 11/01/2012

iphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department

Designing iphone Applications

ITP 342 Mobile App Dev. Connections

What s New in NSCollectionView Session 225

ios Developer s Guide Version 1.0

A Vertical Slider for iphone

Using Swift with Cocoa and Objective-C

CS193p Spring 2010 Wednesday, March 31, 2010

Assignment III: Graphing Calculator

Implementing UI Designs in Interface Builder

ITP 342 Mobile App Dev. Interface Builder in Xcode

iphone Application Tutorial

CS193P: HelloPoly Walkthrough

AVAudioRecorder & System Sound Services

We do More VMAP DOCUMENTATION

Building GUIs with UIKit. Kevin Cathey

ITP 342 Mobile App Dev. Fundamentals

CS193P - Lecture 13. iphone Application Development. Address Book - Putting People in Your App

Assignment I: Concentration

ios 101 Hands-On Challenges

Advanced Memory Analysis with Instruments. Daniel Delwood Performance Tools Engineer

TomTom Mobile SDK QuickStart Guide

ios Application Development Course Details

Mobile Application Development

Navigation bar (Xcode version 4.5.2) 1. Create a new project. From the Xcode menu, select File > New > Project

My First iphone App. 1. Tutorial Overview

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011

Stanford CS193p. Developing Applications for ios. Fall CS193p. Fall

ios Mobile Development

IPHONE DEVELOPMENT. Getting Started with the iphone SDK

Widget Tour. iphone and ipod touch Development Fall 2009 Lecture 7

Introductory ios Development

My First iphone App (for Xcode version 6.4)

Tables. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

NATIVE APP INTERCEPTS on ios & ANDROID

Review. iphone Application Programming Lecture 2: Objective-C, Cocoa. History. Objective-C. Device restrictions. Interaction paradigm changes

Developing Applications for ios

Cocoa Programming A Quick-Start Guide for Developers

NSObject. - (NSString *)description Provides us with a string description of the object

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

CS193P - Lecture 8. iphone Application Development. Scroll Views & Table Views

Real Estate Mobile App Features

AdFalcon ios SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

CS193p Spring 2010 Thursday, April 29, 2010

AVAudioPlayer. avtouch Application

Stanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Fall Stanford CS193p Fall 2010

IOS - TEXT FIELD. Use of Text Field. Important Properties of Text Field. Updating Properties in xib

Stanford CS193p. Developing Applications for ios. Fall CS193p. Fall

Your First iphone OS Application

Your First iphone Application

My First Cocoa Program

Assignment III: Graphing Calculator

ios Core Data Example Application

ITP 342 Mobile App Dev. Unit Testing

Gerontechnology II. Collecting Smart Phone Sensor Data for Gerontechnology. Using ios

ITP 342 Mobile App Dev. Connections

Computer Science 251. iphone Application Development. Autorotation, Popover Controllers, Modal Controllers

Objective-C. Deck.m. Deck.h. Let s look at another class. This one represents a deck of cards. #import <Foundation/Foundation.h> #import "Deck.

Corrections and version notes

Collections & Memory Management. Lecture 2

QuickPrints SDK for ios Version 3.3 August 06, 2014

iphone Programming Touch, Sound, and More! Norman McEntire Founder Servin Flashlight CodeTour TouchCount CodeTour

Transcription:

Overview Create an App that will drop PushPins onto a map based on addresses that the user inputs. Part 1: Introduction to MKMapKit Part 2: Introduction to PushPins Part 3: Use Google s API to lookup an Address Submission Lab evaluation form Lab feedback form(online) Note: If you are unable to complete the lab during this week s lab period, please be ready to demonstrate it at the beginning of the next lab. Page 1 of 5

Part 1. Introduction to MKMapView You will create a simple application that displays Google maps and begin playing with the MapKit Framework. Step 1) Create a new project called FindMe using the View-based application template. Step 2) Add the MapKit Framework to your project. Step 3) Import the MapKit/MapKit.h header in your View Controller header. #import <MapKit/MapKit.h> Step 5) Add an instance of MKMapView to your view using one of the following methods: To add a MKMapView using the Interface Builder: 1. Add an IBOutlet in your header file for an instance of the MKMapView class. 2. Open FindMeViewController.xib in Interface Builder and drag a MKMapView onto the view. 3. Connect a new referencing outlet from the new instance of the MKMapView to your IBOutlet that you created. Or, to add a MKMapView programmatically: 1. Create a class instance variable MKMapView *mapview in FindMeViewController.h. 2. In the viewdidload method, instantiate the instance variable and add it to the view: - (void) viewdidload { [super viewdidload]; mapview = [[MKMapView alloc] initwithframe::self.view.bounds]; [self.view insertsubview:mapview atindex:0]; Step 6) Test your application in the simulator; you should see a map. Step 7) Add the following to your viewdidload method (where mapview refers to your MKMapView instance): mapview.showsuserlocation=true; mapview.maptype=mkmaptypehybrid; Step 8) You can reposition your map using the setregion function of the MKMapView class. MKCoordinateRegion ames; CLLocationCoordinate2D location; location.latitude = 42.02832; location.longitude = -93.65066; ames.center = location; MKCoordinateSpan span; span.latitudedelta = 1.0; span.longitudedelta = 1.0; ames.span = span; [mapview setregion:ames animated:yes]; Step 9) Run your project in the simulator; you should see a map of Ames. Step 10) (DEMO) The final part of this lab can be used to demo all parts of the project at once, or you may demo each Page 2 of 5

Part 2: Introduction to PushPins Reusing your FindMe project from part 1, you will now explore the MKAnnotation protocol, MKPinAnnotationView class and MKMapViewDelegate. You will be able to add Push Pin images to your map at certain latitudes and longitudes. If you want to use your own custom images instead of pushpins, then read the documentation on MKAnnotationView; the implementation is very similar. Create a PushPin Class Step 1) Create a new class called PushPin that subclasses NSObject. Step 2) Import the MKAnnotation header. #import <MapKit/MKAnnotation.h> Step 3) Make your PushPin class implement the MKAnnotation protocol. <MKAnnotation> Hint: At a minimum you should implement the - (id)initwithcoordinate:(cllocationcoordinate2d)coordinate initializer and must have a property named coordinate of type CLLocationCoordinate2D. Right-click on MKAnnotation and Jump to the Definition to see other optional properties to implement. Step 4) Build your project to make sure it is free of errors. Use the PushPin Class in your View Controller Step 5) Import PushPin.h in FindMeViewController.h Step 6) The following code is used to animate adding a push pin to an instance of MKMapView called mapview. CLLocationCoordinate2D location; location.latitude = 42.02832; location.longitude = -93.65066; PushPin *myplace = [[PushPin alloc] initwithcoordinate:location]; [mapview addannotation:myplace]; Add this code in an IBAction that is triggered when a button is pressed. Step 7) Test your code in the simulator. A red push pin should appear on the map when you press the button. Step 8) (DEMO) The final part of this lab can be used to demo all parts of the project at once, or you may demo each Change the Color of the PushPin: The MKMapViewDelegate Protocol Step 9) You can change the color of a PushPin by extending the behavior of the MKMapView class through its delegate. Step 10) Update FindMeViewController.h so it implements the MKMapViewDelegate protocol. Step 11) Set the delegate of you MKMapView instance to the FindMeViewController. You can do this in the Interface Builder by drawing a new connection, or by setting mapview.delegate = self; in the viewdidload method of FindMeViewController.m. Step 12) We must now implement the methods of MKMapViewDelegate. Delegate definitions can have a mix of optional and required methods, so it s good to read the documentation about the delegate interface you re implementing. Documentation: http://beta.devworld.apple.com/iphone/library/documentation/mapkit/reference/mkmapviewdelegate_protocol/mkmapviewdelegate/mkmap ViewDelegate.html Page 3 of 5

Step 13) Implement the mapview:viewforannotation: method of the protocol. CprE 388 Lab 8: Find Me Note: You ll notice that this method is very similar to the implementation of tableview:cellforrowatindexpath: from the UITableViewDelegate used in the last lab. - (MKAnnotationView *) mapview:(mkmapview *)localmapview viewforannotation:(id<mkannotation>)annotation { if ([annotation class]!= [PushPin class]) return nil; MKPinAnnotationView *pin = (MKPinAnnotationView *) [localmapview dequeuereusableannotationviewwithidentifier:@"i"]; if (pin == nil) { pin = [[[MKPinAnnotationView alloc] initwithannotation:annotation reuseidentifier:@"i"] autorelease]; else { pin.annotation = annotation; pin.pincolor = MKPinAnnotationColorGreen; pin.animatesdrop = YES; return pin; Step 14) (DEMO) The final part of this lab can be used to demo all parts of the project at once, or you may demo each Page 4 of 5

Part 3: Use Google s API to lookup an Address In this section, you ll create a UITextField that will allow the user to add a PushPin to the map by typing an address. Step 1) Type the following URL into a web browser: http://maps.google.com/maps/geo?q=ames,%20ia&output=csv You ll notice that it returns four arguments in a comma separated list, the last two being the latitude and longitude for the address in the query. Step 2) Reusing your project from the previous part, alter it so that it queries Google. You may find the following methods very useful: Methods of NSString Class + (NSString *) stringwithformat:(nsstring *)format, - (NSString *) stringbyaddingpercentescapesusingencoding:(nsstringencoding)enc // use NSUTF8StringEncoding + (NSURL *) URLWithString:(NSString *)url; + (NSString *)stringwithcontentsofurl:(nsurl *)url encoding:(nsstringencoding)enc error:(nserror **) &err - (NSArray *) componentsseparatedbystring:(nsstring *)separator Methods of NSURL Class + (NSURL *) URLWithString:(NSString *)url; Methods of NSArray Class - (id) objectatindex:(nsinteger)index Methods of NSNumber - (double) doublevalue Using these methods, you can: 1. Build an NSString of the URL you want to submit to Google. 2. Create a NSURL from that string. 3. Get the results using contentsofurl. 4. Parse the results into an array. 5. Pull out the 3 rd and 4 th objects in the array. Step 3) Demo your project to the TA by typing an address into the UITextField and having a PushPin (not a red PushPin) drop on the map at that given location. Page 5 of 5