How can I get the current location of a user without using gps or internet but by using Network_Provider in Android?

  • Thread starter Thread starter AC Question
  • Start date Start date
A

AC Question

get current location of user without using gps or internet but by using Network_Provider in android

This question is directly related to the same prevailing stackoverflow question at "Android: get current location of user without using gps or internet" where the accepted answer is actually not answering the question. I should be able to get the location of the device via network provider not with GPS or internet. Following is the accepted answer in that question. (The following code parts should be included in the onCreate() method)

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

I changed the above code given in the linked answer as following but no success.

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView txtView = (TextView) findViewById(R.id.tv1);
txtView.setText("ayyo samitha");
////

// Acquire a reference to the system Location Manager
LocationManager 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);

}

private void makeUseOfNewLocation(Location location) {
txtView.setText("sam came in");
txtView.append(location.toString());
}

public void onStatusChanged(String provider, int status, Bundle extras) {}

public void onProviderEnabled(String provider) {
// makeUseOfNewLocation(location);
}

public void onProviderDisabled(String provider) {}
};

// Register the listener with the Location Manager to receive location updates
if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}

}

How to accomplish what I want by correcting above code or any other method? Can somebody please help me.
 
Re: get current location of user without using gps or internet but by using Network_Provider in andr

Since there are going to be many situations in which there's only a single tower face involved, the "location" of the phone is an arc from the tower in a given direction (about 60 degrees wide) on which the phone is a point somewhere between the tower and the horizon - which can easily be 25 miles in some cases. Not much of a "location". (New York City would easily fit inside that "location", and locating a phone to "New York City" is pretty meaningless in most cases.)
 

Trending Posts

Forum statistics

Threads
956,317
Messages
6,967,589
Members
3,163,509
Latest member
JessAnn