What telephonyManager.getCellLocation() method return

◇◆丶佛笑我妖孽 提交于 2019-12-12 01:51:52

问题


I use telephonyManager.getCellLocation() and i get the result which is [-1,-1,0] but i can't understand from the output. Is this any type of location code because i don't think that it is a kind of lat lang of any position. advance thanks for any help


回答1:


You can get locating the position using the LocationManager.NETWORK_PROVIDER instead of LocationManager.GPS_PROVIDER. The NETWORK_PROVIDER will resolve on the GSM or wifi, which ever available. Obviously with wifi off, GSM will be used. Keep in mind that using the cell network is accurate to basically 500m.

http://developer.android.com/guide/topics/location/obtaining-user-location.html has some really great information and sample code.

After you get done with most of the code in OnCreate(), add this:

// 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);

You could also have your activity implement the LocationListener class and thus implement onLocationChanged() in your activity. or you can use this tutorial to get lat and lang.



来源:https://stackoverflow.com/questions/22559459/what-telephonymanager-getcelllocation-method-return

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