Google Service Location API Needs Internet?
Solution 1:
The way it works:
Way 1: Cell Tower Triangulation.(Using Mobile Data)
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);
Way 2: Wifi Connection. Have to be online.
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.
Way 3: GPS. (Offline)
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.
Post a Comment for "Google Service Location API Needs Internet?"