I am learning the Google Maps API V2 and now I am reading about the Location API
, the documents says it connects a client
to the Service
:
Location Services sends the current location to your app through a location client, which is an instance of the Location Services class LocationClient. All requests for location information go through this client.
Does this means that Google will be getting all the positions where my app is? I know Google Maps can work in offline mode if the maps are already downloaded, but does the Location services only function online?
I need to control the internet traffic in my app, so hence the question.
You can use offline maps for reliable navigation and safety features when your car has a poor internet connection. Offline maps can be automatically downloaded and updated based on your current location and travel patterns.
The Geolocation API returns a location and accuracy radius based on information about cell towers and WiFi nodes that the mobile client can detect. This document describes the protocol used to send this data to the server and to return a response to the client. Communication is done over HTTPS using POST.
As mentioned, you won't be charged for your Google Maps API usage until you turn on auto-billing. The free trial limits you to $300 in credit over 90 days. API users also get $200 of credit per month toward API requests, equal to 100,000 static map requests or around 28,000 dynamic map requests per month.
Note that the place ID, used to uniquely identify a place, is exempt from the caching restriction. You can therefore store place ID values indefinitely.
The way it works:
This way uses your service providers Network connection to figure out where you are. The Longitude and Latitude returned are most definitely not the most accurate however, they get you to with 10-15% accuracy (in my experience).
Here is a snippet of code that illustrates this (pulled directly of the Android website)
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
This method is much more accurate than the previous one. However the drawback is that you have to be online and connected to the internet. This method uses the same theory as your JavaScript version of Google maps found on any web browser. The Longitude and Latitude returned by this method are almost exact.
GPS is most accurate, it only works outdoors, it quickly consumes battery power, and doesn't return the location as quickly as users want. However GPS requires no connection to the internet or Mobile data. It gets your location via a request to public satellites.
Here are the two functions you need. getLatitude() and getLongitude().
Keep in mind this is all fun and stuff. But the google maps api v2 has a simple function
mMap.setMyLocationEnabled(true)
;
which considers all three possibilities t get your location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With