We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4
LOCATION SERVICES
• The capability of a smart device to locate itself at a given point of time,
and track its current location, as it moves along with the user, provides location awareness to the apps. • Uses: o Retail outlets can provide an exciting in-store experience by providing in-store offers or mobile brochures. o Banks can guide the user to the nearest Automated Teller Machine (ATM). o Hospitality businesses can help in navigating a user from his or her current location to their nearby food outlets. • Functionalities: o Locating the User ▪ The most primitive task of the Location services is to provide the current location of a user. ▪ Mobile devices use several techniques to determine their location. Unique cell id of the nearest cellular tower can be used to approximately determine the current location. If the device is receiving signals from two or more towers simultaneously, cell triangulation technique can be used for better accuracy. ▪ The IP address of Wi-Fi network to which the device is connected, can also be used to determine the location. ▪ All these techniques do not require a dedicated hardware in the device, and vary in accuracy. However, ▪ Location can be accurately determined using GPS (Global Positioning System), a dedicated hardware in the device. o Code (9.2, 9.3): ▪ The LocationClient constructor used to instantiate mClient accepts three parameters – context, class implementing ConnectionCallbacks interface, and class implementing onConnectionFailedListener interface ▪ The getCurrentLocation() method is invoked on click of the Get Location Button . ▪ an instance of the LocationClient – mClient – is used to retrieve the location of the user. ▪ The getLastLocation() method of the LocationClient returns a Location object containing the last known coordinates. o Tracking User Location: ▪ Location services not only determine location when the device is stationary, as seen in the previous example, but also have the capabilities to do the same while it is moving. ▪ This will come handy in those scenarios where an app needs to process the continuous location updates such as computing the speed of the user while running or the distance covered while cycling. o Code (9.4): ▪ onLocationChanged() method, where we display the location coordinates every time the location changes. ▪ We have defined a method setUpLocationParams() to create and configure the LocationRequest object for location updates. ▪ Here we are configuring the location update interval using the setInterval() method, and setting its value as 5000 ms . ▪ In case another app on the same device is also using Location services and has a shorter update interval, our app will get updated more frequently than desired. In such cases, the setFastestInterval() method comes handy to restrict our app to not receive the location updates below the limit set in this method, which is 2000 ms in our case . o Retrieving Location Address: ▪ Location-aware apps, typically, perform various tasks after determining the current location coordinates. ▪ This process of determining the street address from the location coordinates is referred to as reverse geocoding. Android facilitates this process using the Geocoder API. o Code (9.5): ▪ The getCurrentAddress() method is called on tap of the Get Address Button. ▪ Once this is ensured, we can use the getFromLocation() method of the Geocoder to retrieve the location address based on the latitude and longitude. ▪ There might be several street addresses that are mapped to a specific latitude–longitude; therefore, the getFromLocation() method may return multiple street addresses. ▪ Street address(es) is retrieved as a list of Address object(s) wherein each address is a set of Strings. ▪ We can retrieve various address-related information from these set of Strings such as address line, country code, country name, locale, locality, and postal code. we have retrieved the address line, locality, and country name using the getAddressLine(), getLocality(), and getCountryName() methods, respectively. Flowchart for flow control locating user code: