Hello Readers!! Hope you are doing well. Today we shall cover one of the most interesting and interactive lesson. This spice of android cuisine makes it more delicious. It is my favorite topic and I am really excited to do this tutorial for you. Hope you too enjoy this section of tutorial as I do. Let us not waste any more time and start learning.
Maps and location-based services use latitude and longitude to determine geographic locations. The maps library includes a geo-coder that we can use to convert back and forth between latitude/longitude values and real-world addresses. Location awareness improves many applications and makes possible totally new applications. If we talk about the popularity and economic strategy of mobile market the location awareness of smart phones generates more revenue. In other words, smart phones are smart because they know their location. Location is usually combined with search.
We have the following location strategies:
- Triangulation: In this process the location of a particular point is determined by considering it as the third point of triangle with one known side and two known angles. In other words, we are aware of the baseline and two angles, hence we determine the third position be the intersection of these two angles.
- Cell ID: Our mobile phones are always under the constant inspection of cell towers. It is mandatory as cell phone users may go anywhere and they should receive the call from any corner of the world. Each cell tower has a unique identifier which is called Cell ID. Each tower knows its latitude and longitude. We can say each mobile phone know its approximate location.
- GPS Overview: The Global Positioning System (GPS) is a space-based satellite navigation system. It provides location and time information anywhere and everywhere on the surface of earth. A GPS receiver calculates its position by precisely timing the signals sent by GPS satellites. Each satellite continuously transmits messages:
- the time the message was transmitted
- satellite position at time of message transmission
The GPS receiver uses the following information to determine a position.
1. Precise location of satellites: When a GPS receiver downloads orbit information from all the satellites which is called an almanac. It is stored in the receiver’s memory for future use.
2. Distance from satellite: The distance from each satellite to the receiver is calculated by GPS receiver. The distance formula is used which says, distance = velocity x time. The receiver would be aware of velocity. It is the speed of a radio wave or 186,000 miles per second. The receiver determines time by considering the fact that how long it takes for a signal from the satellite to arrive at the receiver. Distance is determined by multiplying velocity and time.
3. Triangulation: It is used to determine position. In this scenario, the receiver locates position by using triangulation. The receiver catches signals from at least three satellites. 2D position can be calculated by the receiver with this formula. At least four or more satellites are required to calculate a more perfect 3D position. The position is usually reported in latitude/longitude, UTM, or other coordinate system.
10.1.2 Android: Location Based Services
A location-based service is a versatile service which is used to describe the different technologies. They are used to find a device’s current location. The two principal location based service elements are:
- Location Manager Provides hooks to the location-based services
- Location Providers Each of these represents a different location-finding technology used to determine the device’s current location
With Location Manager, we can do following things:
- Obtain your current location
- Track movement
- Set proximity alerts for detecting movement into and out of a specified area
- Find available Location Providers
There may be several technologies that Android can use to determine the current location but it depends on the device. Each technology, or Location Provider, offers various capabilities, which includes differences in power consumption, monetary cost, accuracy, and the ability to determine altitude, speed, or heading information. We call getProvider to get an instance of particular provider by passing in the name:
String providerName = LocationManager.GPS_PROVIDER; LocationProvider gpsProvider; gpsProvider = locationManager.getProvider(providerName);
This is generally useful only for determining the abilities of a particular provider. Most Location Manager Methods needs only a provider name to perform location-based services.
In most scenarios it’s unlikely that you will want to explicitly choose the Location Provider to use. We will specify the requirements that a provider must meet and Android would determine the best technology to apply in the particular situation. Criteria class is used to dictate the requirements of a provider when we talk about accuracy (fine or coarse), power usage (low, medium, high), financial cost, and the ability to return values for speed, altitude and bearing.
For finding the physical location of the device we use the location-based services. Access to the location-based services is handled by the Location Manager system Service. To access the Location Manager, request an instance of the LOCATION_SERVICE using the getSystemService method, as shown in the following snippet:
String serviceString = Context.LOCATION_SERVICE; LocationManager locationManager; locationManager = (LocationManager)getSystemService(serviceString);
The LocationManager class includes static string constants that return the provider name for three Location Providers:
Congratulations buddies!! We are done with our basic understanding of location providers. We shall start doing examples from next sub-section. See you in the next section. Till then keep practicing the previous examples. Happy App Developing!!