Skip to content Skip to sidebar Skip to footer

What Telephonymanager.getcelllocation() Method Return

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

Solution 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 ManagerLocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updatesLocationListener locationListener = newLocationListener() {
publicvoidonLocationChanged(Location location) {
  // Called when a new location is found by the network location provider.makeUseOfNewLocation(location);
}

publicvoidonStatusChanged(String provider, int status, Bundle extras) {}

publicvoidonProviderEnabled(String provider) {}

publicvoidonProviderDisabled(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.

Post a Comment for "What Telephonymanager.getcelllocation() Method Return"