Google Service Location API needs internet?

痞子三分冷 提交于 2019-12-01 00:32:10

问题


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.


回答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.



来源:https://stackoverflow.com/questions/24665177/google-service-location-api-needs-internet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!