Android Location Api

11
GPS Access 1 Android application development

description

National Mobile Application Awareness Development & Capacity Building Program (Android Slides)

Transcript of Android Location Api

Page 1: Android Location Api

1

GPS Access

Android application development

Page 2: Android Location Api

2

GPS Technology: Simplified• The Global Positioning System (GPS) is a satellite-based navigation system made up of a network of 24 satellites placed into orbit by the U.S. Department of Defense. • GPS was originally intended for military applications, but in the 1980s, the government made the system available for civilian use. • GPS works in any weather conditions, anywhere in the world, 24 hours a day. • There are no subscription fees or setup charges to use GPS.

Page 3: Android Location Api

3

GPS Technology: Simplified (Contd.)• Global Positioning System satellites transmit signals to equipment (receivers) on the

ground. GPS receivers passively receive satellite signals; they do not transmit. • GPS receivers require an unobstructed view of the sky• Depend on a very accurate time reference, which is provided by atomic clocks at the

U.S. Naval Observatory. Each GPS satellite has atomic clocks on board.• Each GPS satellite transmits data that indicates its location and the current time. • All GPS satellites synchronize operations so that these repeating signals are transmitted

at the same instant. • The signals, moving at the speed of light, arrive at a GPS receiver at slightly different

times because some satellites are farther away than others. • The distance to the GPS satellites can be determined by estimating the amount of time

it takes for their signals to reach the receiver. • When the receiver estimates the distance to at least four GPS satellites, it can calculate

its position in three dimensions.• There are at least 24 operational GPS satellites at all times. The satellites, operated by

the U.S. Air Force, orbit with a period of 12 hours.

Page 4: Android Location Api

4

GPS Technology: Determining Position

Page 5: Android Location Api

5

GPS Access

1. Create a project Named “UseGps”2. We need to add some permissions to use GPS and Internet

Page 6: Android Location Api

6

GPS Access3. Now we need add a location listener, so each time the GPS senses a new location, this callback function will be called from the android system.

To do this, we need to add the fallowing code in the onCreate() method:

Page 7: Android Location Api

7

GPS Access4. We now have to create MyLocationListener class that implements LocationListener and Implement methods for various events:

· onLocationChanged ( Location Update )· onProviderDisabled ( GPS Off )· onProviderEnabled (GPS On )

Page 8: Android Location Api

8

GPS Access

5. Now we run the app in emulator and use emulator control to emulate the GPS module

Page 9: Android Location Api

9

GPS Access

6. Now we’ll add a webview to main.xml layout and show the location in a map

7. Capture the webview by findViewById()

Page 10: Android Location Api

10

GPS Access

8. Now when the location is changed

9. Lets run it again

Page 11: Android Location Api

11

GPS Access