Is it possible to get the current location of user without using GPS or the internet? I mean with the help of mobile network provider.
- 1Does the accepted answer works perfectly? For me it is not working...!!!Samitha Chathuranga– Samitha Chathuranga2015-05-01 17:15:29 +00:00Commented May 1, 2015 at 17:15
- 3Unfortunately the accepted answer is wrong :-( Amazing that it got 28 upvotes even though it doesn't answer the question correctly!David Wasser– David Wasser2015-05-08 13:23:35 +00:00Commented May 8, 2015 at 13:23
- @DavidWasser Appreciate your valuable comments. And do you think that there is actually no any method to get the location details without using internet or gps? (other than by using that cell broadcast messages)Samitha Chathuranga– Samitha Chathuranga2015-06-14 06:58:31 +00:00Commented Jun 14, 2015 at 6:58
- 2@SamithaChathuranga Think about this: if you have no GPS and you have no Internet, where are you going to get this information? You can get the cell ID information from the network. This gives you only the ID. You would then need a way to map the ID to an actual coordinate or name. You could always build your own cell ID database and include it in your application, but it would take you an awful lot of work to collect all that data and the mapping isn't static: it changes as mobile operators install new cell towers and renumber their networks. Basically, the practical answer is "no".David Wasser– David Wasser2015-06-14 19:52:09 +00:00Commented Jun 14, 2015 at 19:52
- @DavidWasser Thanks for the reply. I also had a big surprise how to get the location without internet or gps. But including stackoverflow in many forums this is said to be possible. That's why I thought it will be possible. Seems a lot of people are misguided too.Samitha Chathuranga– Samitha Chathuranga2015-06-15 03:21:39 +00:00Commented Jun 15, 2015 at 3:21
8 Answers
What you are looking to do is get 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.
15 Comments
By getting the getLastKnownLocation you do not actually initiate a fix yourself.
Be aware that this could start the provider, but if the user has ever gotten a location before, I don't think it will. The docs aren't really too clear on this.
According to the docs getLastKnownLocation:
Returns a Location indicating the data from the last known location fix obtained from the given provider. This can be done without starting the provider.
Here is a quick snippet:
import android.content.Context; import android.location.Location; import android.location.LocationManager; import java.util.List; public class UtilLocation { public static Location getLastKnownLoaction(boolean enabledProvidersOnly, Context context){ LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Location utilLocation = null; List<String> providers = manager.getProviders(enabledProvidersOnly); for(String provider : providers){ utilLocation = manager.getLastKnownLocation(provider); if(utilLocation != null) return utilLocation; } return null; } } You also have to add new permission to AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 8 Comments
PASSIVE_PROVIDER, NETWORK_PROVIDER, and GPS_PROVIDER.No, you cannot currently get location without using GPS or internet.
Location techniques based on WiFi, Cellular, or Bluetooth work with the help of a large database that is constantly being updated. A device scans for transmitter IDs and then sends these in a query through the internet to a service such as Google, Apple, or Skyhook. That service responds with a location based on previous wireless surveys from known locations. Without internet access, you have to have a local copy of such a database and keep this up to date. For global usage, this is very impractical.
Theoretically, a mobile provider could provide local data service only but no access to the internet, and then answer location queries from mobile devices. Mobile providers don't do this; no one wants to pay for this kind of restricted data access. If you have data service through your mobile provider, then you have internet access.
In short, using LocationManager.NETWORK_PROVIDER or android.hardware.location.network to get location requires use of the internet.
Using the last known position requires you to have had GPS or internet access very recently. If you just had internet, presumably you can adjust your position or settings to get internet again. If your device has not had GPS or internet access, the last known position feature will not help you.
Without GPS or internet, you could:
- Take pictures of the night sky and use the current time to estimate your location based on a star chart. This would probably require additional equipment to ensure that the angles for your pictures are correctly measured.
- Use an accelerometer to track location starting from a known position. The accumulation of error in this kind of approach makes it impractical for most situations.
Comments
boolean gps_enabled = false; boolean network_enabled = false; LocationManager lm = (LocationManager) mCtx .getSystemService(Context.LOCATION_SERVICE); gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); Location net_loc = null, gps_loc = null, finalLoc = null; if (gps_enabled) gps_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (network_enabled) net_loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (gps_loc != null && net_loc != null) { //smaller the number more accurate result will if (gps_loc.getAccuracy() > net_loc.getAccuracy()) finalLoc = net_loc; else finalLoc = gps_loc; // I used this just to get an idea (if both avail, its upto you which you want to take as I've taken location with more accuracy) } else { if (gps_loc != null) { finalLoc = gps_loc; } else if (net_loc != null) { finalLoc = net_loc; } } Comments
Here possible to get the User current location Without the use of GPS and Network Provider.
1 . Convert cellLocation to real location (Latitude and Longitude), using "http://www.google.com/glm/mmap"
Comments
Have you take a look Google Maps Geolocation Api? Google Map Geolocation
This is simple RestApi, you just need POST a request, the the service will return a location with accuracy in meters.
Comments
It appears that it is possible to track a smart phone without using GPS.
Sources:
Primary: "PinMe: Tracking a Smartphone User around the World"
Secondary: "How to Track a Cellphone Without GPS—or Consent"
I have not yet found a link to the team's final code. When I do I will post, if another has not done so.