web 2.0 and iphone application development workshop lab 7…work1803/labs/lab7.pdf ·  ·...

5
Location base application 1 Web 2.0 and iPhone Application Development Workshop This lab is prepared by: Department of Electrical and Electronic Engineering, Faculty of Engineering, The University of Hong Kong Lab 7: Location base application Objective: This is a training program for the students to create an iPhone Application which can locate where the user is. After this lab session, students should know how an iPhone Application read the input raw longitude and latitude values form the device and implement an iPhone application with your own custom map. Introduction: In order to build a Location-based iPhone application, there are mainly two methods to obtain the required data. The first method is to use the GPS chip in the iPhone device to get raw data directly from the satellites. The second method is to use the WiFi-base geo-detection technology, which the iPhone device can obtain the raw longitude and latitude value from the server base on the location of the WiFi hotspots you are connected to. In this lab session, we will focus on the latter method, that is, a WiFi-based geo-detection iPhone Application. Although there is a build-in map for iPhone devices, this time, we will use a custom map instead. Equipment: 1. A Macintosh computer with iPhone SDK installed. 2. An iPhone device such as iPhone or iPod touch. 3. iPod USB cable.

Upload: dinhphuc

Post on 11-May-2018

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Web 2.0 and iPhone Application Development Workshop Lab 7…work1803/labs/lab7.pdf ·  · 2010-06-021. Download the file “lab7.zip” from the server. ... Location base application

Location base application 1

Web 2.0 and iPhone Application Development Workshop

This lab is prepared by:

Department of Electrical and Electronic Engineering,

Faculty of Engineering,

The University of Hong Kong

Lab 7: Location base application

Objective:

This is a training program for the students to create an iPhone Application which can locate

where the user is. After this lab session, students should know how an iPhone Application

read the input raw longitude and latitude values form the device and implement an iPhone

application with your own custom map.

Introduction:

In order to build a Location-based iPhone application, there are mainly two methods to

obtain the required data. The first method is to use the GPS chip in the iPhone device to get

raw data directly from the satellites. The second method is to use the WiFi-base

geo-detection technology, which the iPhone device can obtain the raw longitude and

latitude value from the server base on the location of the WiFi hotspots you are connected

to. In this lab session, we will focus on the latter method, that is, a WiFi-based geo-detection

iPhone Application.

Although there is a build-in map for iPhone devices, this time, we will use a custom map

instead.

Equipment:

1. A Macintosh computer with iPhone SDK installed.

2. An iPhone device such as iPhone or iPod touch.

3. iPod USB cable.

Page 2: Web 2.0 and iPhone Application Development Workshop Lab 7…work1803/labs/lab7.pdf ·  · 2010-06-021. Download the file “lab7.zip” from the server. ... Location base application

Location base application 2

Duration:

The duration of this training lab session is about 1.5 hours.

Procedure:

1. Download the file “lab7.zip” from the server. Extract it to your Macintosh computer.

2. In the zip file, you can find the folder called “accelerometer”. Open this and open

“������������ ���������”. It is the template for this lab session.

3. In order to read the raw longitude and latitude values of the user’s position, a

framework called “������ ���������” should be included in the project. Right click

“Frameworks” from “Groups & Files”, choose “Add > Existing Frameworks…”, choose

“������ ���������”.

After that, go to “�������������������������� �” and add the following line:

Page 3: Web 2.0 and iPhone Application Development Workshop Lab 7…work1803/labs/lab7.pdf ·  · 2010-06-021. Download the file “lab7.zip” from the server. ... Location base application

Location base application 3

4. As you can see from “�������������������������� �”, there are all together 7

�������� objects. Please open “�������������������������� ��” from “Groups

& Files > Resources > location_basedViewController.xib”. Map the �������� objects to

the objects in the interface builder (2 of them are done for you). Remember to map the

“Received Actions” to the �������� object as well. Save the file after you’ve done.

Page 4: Web 2.0 and iPhone Application Development Workshop Lab 7…work1803/labs/lab7.pdf ·  · 2010-06-021. Download the file “lab7.zip” from the server. ... Location base application

Location base application 4

5. In order to match the custom map to a real map, we need to know the longitude and

latitude of the 4 corners of the custom map. Open your browser and go to:

http://itouchmap.com/latlong.html. You can find the longitude and latitude value of

any point on the map. Try to find the longitude and latitude values of the 4 corners

from iTouchMap.

6. Open “�������������������������� �” in the Xcode from “Groups & Files >

Classes > location_basedViewController.m”. Search for the function “���� ��!���” by

using “command + F”. Write down what you have found:

7. There is a self-defined function called “"���#!�������������”, the following 2 lines

capture the information of user’s position:

Given that the size of the custom map is 1246px x 588px. Find the relationship between

the changes in longitude/latitude value and the changes in height/width.

Page 5: Web 2.0 and iPhone Application Development Workshop Lab 7…work1803/labs/lab7.pdf ·  · 2010-06-021. Download the file “lab7.zip” from the server. ... Location base application

Location base application 5

8. The x-coordinate of �#!������� can be found by the following formula:

Find the formula of finding the y-coordinate of �#!�������.

9. You may now test your program. Choose “iPhone Device” and then click “Build and

Run”. Check whether it can show your location or not.

- End of Lab 7 -