Get current location of user in Android without using GPS or internet
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.
Get current location name of user without using gps or internet but by using Network_Provider in android
What you are referring to here (showing location name on older phones) is done using "Cell Broadcast" (or "CB"). This has absolutely nothing to do with the Location API or any variations on that.
Cell towers can send out broadcast information that can be received by devices (something like "one to many SMS"). Some operators have used Cell Broadcast to broadcast the name of the location where the cell tower is. Some operators have used Cell Broadcast to broadcast the location (lat/long) of the cell tower. Some operators have used Cell Broadcast to send advertising tickers. There are no standards for the information contained in a CB broadcast message and each mobile operator can choose to use this or not.
Since most operators do not send these messages, it probably doesn't make sense to invest any time in trying to receive and decode them. But if you want to try, you can register a BroadcastReceiver
listening for this Intent
action: android.provider.Telephony.SMS_CB_RECEIVED
. See the documentation for more details about what data is contained in the Intent
.
How to get user location without gps or wifi?
Here is my stripped down Location Service I am using right now. GPS and Network are called Providers in this context.
I've changed the way my logic works, where it checks which provider is enabled and then returns the best one that's enabled (GPS is better then network), to this line: String providerToSend = providers.get(1);, in the GetProvider method.
So instead of checking each provider, this way it chooses providers.get(1), which is always the string NETWORK. Feed that to your locationManager.getLastKnownLocation(TheStringWithTheCorrectProviderGoesHere), and it'll return your position.
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import java.util.List;
public class LocationService extends Service implements LocationListener{
protected LocationManager locationManager;
public String providerNow;
private List<String> providers;
public Location location;
private final Context mContext;
public LocationService(Context context) {
Log.i("TestMap", "LocationService");
this.mContext = context;
locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,0,this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,1000,0,this);
providerNow = (GetProvider());
}
public Location getLocation() {
location = locationManager.getLastKnownLocation(providerNow);
return location;
}
public String GetProvider (){
Criteria criteria = new Criteria();
criteria.setAccuracy(2);
providers = locationManager.getProviders(true);
String providerToSend = providers.get(1);
return providerToSend;
}
public IBinder onBind(Intent intent) {
Log.i("TestMap", "onBind");
//TODO for communication return IBinder implementation
return null;
}
public void onLocationChanged(Location location) {
Location locationNew = location;
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
providerNow = (GetProvider());
}
@Override
public void onProviderDisabled(String provider) {
providerNow = (GetProvider());
}
}
Locating current position in android without GPS
You should request 'mlocManager' to locate, and set its listener:
public void getCurrentLocation()
{
if (mlocManager != null) {
mlocManager .requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, locListener );
mlocManager .requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, locListener );
}
}
Location tracking system without using internet in android
Have you try LocationManager class in android. This class allow user to request location by gps and network provider both.
FusedLocationProvider is latest android api to get location
Related Topics
Ffmpeg for a Android (Using Tutorial: "Ffmpeg and Android.Mk")
Reading an Image File into Bitmap from Sdcard, Why am I Getting a Nullpointerexception
How to Get Access to Raw Resources That I Put in Res Folder
Share Sqlite Database Between 2 Android Apps
How to Do a Simple Search in String in Firebase Database
How to Enable Tls 1.2 Support in an Android Application (Running on Android 4.1 Jb)
How to Add a Notification Badge/Count to Application Icon on Sony Xperia Devices
Adb Not Responding - Wait More or Kill Adb or Restart (Ubuntu 13) 64-Bit
What Should I Use Android Accountmanager For
Android Overriding Onbackpressed()
Referencing a String in a String Array Resource with Xml
Get Altitude by Longitude and Latitude in Android
How to Create a Notification with Notificationcompat.Builder
What Is the Relation Between App_Platform, Android:Minsdkversion and Android:Targetsdkversion
How to Create Empty Constructor for Data Class in Kotlin Android