I want to get my current latitude and longitude using Mobile network provider, not GPS. AKA it should work without GPS with just your sim card. i have found many tutorials online claiming they find location with gps or network. however, they all seem to use GPS only! here or here and also here i don't want last knows location, as i don't wish to use GPS
Asked
Active
Viewed 6,792 times
-3
-
1Possible duplicate of [Android: get current location of user without using gps or internet](http://stackoverflow.com/questions/6694391/android-get-current-location-of-user-without-using-gps-or-internet) – Niels Masdorp Apr 08 '16 at 13:08
-
you should open the link that @Niels Masdorp sends to you. The first Phrase says : " Is it possible to get the current location of user without using gps or internet? I mean with the help of mobile network provider. Can anyone help me?" – Lucas Ferraz Apr 08 '16 at 13:14
-
the link did not solve my problem – abbie Apr 08 '16 at 13:15
-
1That doesn't mean it is not a duplicate question. The accepted answer clearly shows how to get a users location without GPS by using the network provider. – Niels Masdorp Apr 08 '16 at 13:15
-
I am supposed to ask a New question if researching doesn't solve my issue. – abbie Apr 08 '16 at 13:17
-
1Actually you are not supposed to ask the exact same question when some solution does not work. At least specify in your question that you tried the solution and your results. – Niels Masdorp Apr 08 '16 at 13:18
-
"the link did not solve my problem" -- feel free to explain, in detail, what you tried and what specific problems you encountered, in part by supplying a [mcve]. – CommonsWare Apr 08 '16 at 13:59
2 Answers
0
Try This Code you can get current location without opening GPS
btnNWShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Location nwLocation = appLocationService
.getLocation(LocationManager.NETWORK_PROVIDER);
if (nwLocation != null) {
double latitude = nwLocation.getLatitude();
double longitude = nwLocation.getLongitude();
Toast.makeText(
getApplicationContext(),
"Mobile Location (NW): \nLatitude: " + latitude
+ "\nLongitude: " + longitude,
Toast.LENGTH_LONG).show();
} else {
showSettingsAlert("NETWORK");
}
}
});

Hafizur Rahman Shaik
- 111
- 1
- 5
-2
Do it via 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);

user229044
- 232,980
- 40
- 330
- 338

Anirudh Loya
- 173
- 7
-
After you get done with initialisation & other code in OnCreate() – Anirudh Loya Apr 08 '16 at 13:18
-
Can you tell me what is "makeUseOfNewLocation(location);" if you really didn't steal this snippet from this answer? http://stackoverflow.com/questions/6694391/android-get-current-location-of-user-without-using-gps-or-internet – abbie Apr 08 '16 at 13:18
-
-
Here's the link to my Snippet http://developer.android.com/guide/topics/location/strategies.html Available for all.. ! – Anirudh Loya Apr 08 '16 at 13:20
-