Tip:
Highlight text to annotate it
X
In this lecture, I will introduce bada's Location namespace.
I will briefly introduce the Location namespace, the Location Provider, the Landmark and the
Location Service. Then I will talk about the Map control used
to display a map on the screen. bada's Location namespace basically provides
functions to get the location of the current device (or of other devices), and functions
to search for and manage landmarks. Using this namespace, you can develop applications
using Location Based Services.
Now, I will talk about the sub namespaces of the Location namespace.
The Location namespace contains classes to get the current position of the user and classes
to get the remote locations of other devices. The landmark, landmark store and remote landmark
store classes perform roles to manage the points of interest through the database.
Location services include the map, Geocoding, route and directory services.
The UI controls that display location related information on the screen are also provided.
Let's have a look at the LocationProvider class that returns the current location in
detail. The LocationProvider class contains APIs that
belong to the LOCATION privilege group. The LocationProvider class is used to get
the current location of the device, using either the GPS of the device or the surrounding
Wi-Fi access points. The LocationProvider class also has a function
to report the current location at a pre-determined interval.
The location is returned in the Location class. The Location class provides the coordinates
to figure out the current position, the direction and velocity, the time stamp, the method used
to get the location and if there is a GPS, the satellite information for the GPS.
A listener is used to deliver the Location information to an application.
There are functions that manage listeners such as the RequestLocationUpdate, CancelLocationUpdate
and AddAreaListener functions. First, the RequestLocationUpdate function
reports the current position at a pre-determined interval, through the registered listener
whenever the location changes. The CancelLocationUpdate function is used
to delete the listener registered in the RequestLocationUpdate function.
Finally, the AddAreaListener function calls a specific function of the listener object
when the location moves out of or enters a pre-determined area.
You can delete the listener using the RemoveAreaListener function.
Let's see how we can use the LocationProvider class.
The first method is acquiring the location on a regular basis using the LocationProvider
class. Since this method consumes a lot of resources,
using this function widely is not recommended. To use this method, call the GetRequestLocationupdates
function during the initialization, then add the listener.
Then, the listener function in the listener object is called periodically.
You can get the location through the listener. If the application changes to the background,
the location update operation is cancelled using the CancelLocationUpdates function,
to save battery power. If the application returns to the foreground,
the listener is registered and the RequestLocationUpdates function is called.
Then, the location is updated periodically. Finally, if the application is terminated,
the location update is stopped using the CancelLocationUpdates function.
The second scenario is to perform monitoring for when the device moves out of the specified
area. In the initialization process, the current
location is acquired and you can specify whether to receive the notification when the device
moves out of the area specified around the current location.
First, to get the more recently reported location, the GetLastKnownLocationN function is used.
The shape and radius of the area around this location are set and the values are passed
to the AddAreaListener function in order to add the listener.
Then, if the device moves out of the area, you can receive the notification through the
listener function. When this occurs, the OnBoundaryCrossed function
of the listener object is called. If the device moves out of the boundary and
the OnBoundaryCrossed function is called, you can set the AddAreaListener to specify
a new area. If the application is terminated after the
listener is added, you have to delete the AreaListener by calling the RemoveAreaListener
function.
This last scenario only updates the location when the application needs to be updated.
As this method consumes much less battery power than the conventional periodic update
of the location, this should be used when it is not necessary to update the location
periodically. In this case, you can get the most recently
updated location using the GetLastKnownLocationN function.