delight-im / android-simplelocation Goto Github PK
View Code? Open in Web Editor NEWUtility class for easy access to the device location on Android
License: Apache License 2.0
Utility class for easy access to the device location on Android
License: Apache License 2.0
Hi there is this library working on background process in order to get latest location in android 6 above.tq
Hi marco! Thanks for your wonderful library.
I came up with two minor issues. First one is that the speed is always zero!
Second one is how can I decrease intervals in locationChangeListener? It always updates with 20 seconds!
Hi Team, this library simplified lot of works. But in my application i am using background service to update user current location using alarmManager & Service.
1. If user is in online then i send data to server. If not storing into Room Database.
2. Every 5 minutes i updating location details.
3. If i am in travel, after reached new location its not updating new location, when i open my app then . only its updating new location and sending to server
Please help me if i am wrong. Thanks!
`
class AppService : Service() {
var NOTIFICATION_ID = "notification-id"
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
val context = this
val location = SimpleLocation(context)
val address = getAddress(context, location.latitude, location.longitude)
if (isConnectedOrConnecting(context)) {
AppUtil.addAttendance(getLatLng(context), address, context)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notification = getNotification(context, "Hai, sent your location$address")
val id = intent.getIntExtra(NOTIFICATION_ID, 0)
notificationManager.notify(id, notification)
roomDB = Room.databaseBuilder(this, LocationDataBase::class.java, "location_db").allowMainThreadQueries().build()
val list = roomDB.locationModel().listOfLocation
sendSavedDataToServer(list, this)
} `
In many phones its working perfect but in few phones lag lng is zero all the time. any solution?
Hi, I followed the instructions in the readme file. But result Lat: 0.0, Lon: 0.0
`package app.meysta;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import im.delight.android.location.SimpleLocation;
public class Splash extends Activity {
private SimpleLocation location;
double latitude =1;
double longitude = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_splash);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
location = new SimpleLocation(Splash.this, true, false, 5 * 1000, true);
// if we can't access the location yet
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(Splash.this);
}
TextView txt = (TextView)findViewById(R.id.txtt);
txt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
latitude = location.getLatitude();
longitude = location.getLongitude();
Log.i("Lokasyon", String.valueOf(latitude)+","+longitude);
location.beginUpdates();
}
});
location.setListener(new SimpleLocation.Listener() {
public void onPositionChanged() {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
});
}
@Override
protected void onResume() {
super.onResume();
// make the device update its location
location.beginUpdates();
latitude = location.getLatitude();
longitude = location.getLongitude();
// ...
}
@Override
protected void onPause() {
// stop location updates (saves battery)
location.endUpdates();
// ...
super.onPause();
}
}
`
precise only up to 3 digits of longitude & latitude,4th digit is crucial to me ..can u implement this more accurately
Hi, can you implement de getAccuaracy() :) ๐
Thxs!
Please can you show gradle compile code on home screen.
I have tried to read the readme and I have tried to search in the 'issues' section, but I can't find documentation about the difference between passiveMode == true and passiveMode == false
could you please help us to explain about this parameter ?
Both latitude and longitude is 0.0.
Method Calculate not found.
This is how I am doing but I am always getting Lat and Long values 0.0
```
// construct a new instance of SimpleLocation
location = new SimpleLocation(this);
// if we can't access the location yet
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(this);
}
findViewById(R.id.someview).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final double latitude = location.getLatitude();
final double longitude = location.getLongitude();
mLatitudeText.setText("Lat " +
"" + location.getLatitude());
mLongitudeText.setText("Long " +
"" + location.getLongitude());
}
});
// construct a new instance of SimpleLocation
location = new SimpleLocation(this);
// if we can't access the location yet
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(this);
}
findViewById(R.id.someview).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final double latitude = location.getLatitude();
final double longitude = location.getLongitude();
mLatitudeText.setText("Lat " +
"" + location.getLatitude());
mLongitudeText.setText("Long " +
"" + location.getLongitude());
}
});
I am using Samsung A5 Android lollipop
Sorry for disturbing .. I am trying the code on emulator.
I've just copy+paste the code from Readme file and it returns 0.0 .
Here is my code ;
public class MainActivity extends AppCompatActivity {
private SimpleLocation location;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextEdit tw1 = (TextEdit) findViewById(R.id.textView);
final TextEdit tw2 = (TextEdit) findViewById(R.id.textView2);
// construct a new instance of SimpleLocation
location = new SimpleLocation(this);
// if we can't access the location yet
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(this);
}
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final double latitude = location.getLatitude();
final double longitude = location.getLongitude();
tw1.setText("Lat: "+latitude);
tw2.setText("Lng: "+longitude);
// TODO
}
});
}
@Override
protected void onResume() {
super.onResume();
// make the device update its location
location.beginUpdates();
// ...
}
@Override
protected void onPause() {
// stop location updates (saves battery)
location.endUpdates();
// ...
super.onPause();
}
Hi there!
First of all, I would like to thank you for this awesome library. It does help me with my project, also I'm relatively new to Android programming. However, I'm having a small issue that maybe you could help me with. I've followed the instructions on the README file. Everything is running smoothly but then I realized that the first coordinates I received did not update afterward. It keeps giving the same exact coordinates every 10 seconds even when I go out for running.
Note: I've used a Runnable for this to save the coordinate values every 10 seconds into .csv file until I pressed a button to stop it.
In MainActivity
file:
private SimpleLocation mLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("onCreate", "onCreate");
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 123);
}
mLocation = new SimpleLocation(this);
if (!mLocation.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(this);
}
}
private Runnable mGPSRunnable = new Runnable() {
@Override
public void run() {
final double latitude = mLocation.getLatitude();
final double longitude = mLocation.getLongitude();
Log.d("GPS", "Lat: " + latitude + " Long: " + longitude);
mHandler.postDelayed(this, 10000);
saveGPSData(); // saves the values in .csv file
}
};
The two methods below are assigned to one button each:
public void startGPS() {
mGPSRunnable.run();
mLocation.beginUpdates();
}
public void stopGPS() {
mHandler.removeCallbacks(mGPSRunnable);
mLocation.endUpdates();
}
Did I forget something here?
My apologies for the long post. I would really appreciate if you can help me with this :)
Is possible get de Lat and Long with the Address in this library?
When it changes the position it is not updating the latitude and longitude so giving old values instead of giving new latitude and longitude values.
location.setListener(new SimpleLocation.Listener() {
public void onPositionChanged() {
// new location data has been received and can be accessed
latitude_user = location.getLatitude();
longitude_user = location.getLongitude();
}
Error:(34, 13) Failed to resolve: com.github.delight-im:Android-SimpleLocation:v1.0.1
I am using this library to get the location. But when GPS is not On and we turn on it by going to settings which opens from location.openSettings() method. In this case the location is coming as 0. How to get correct location?
Hi,
I am using this in my background service.It is working perfectly fine when we are in app but when app is in background it work for 3-5 times then it start showing same location again and again.
Please help me as early as possible.
When i set the requireFine parameter of any of the constructors to true, i get 0.0 coordinates, but when i use the single-param constructor(defaulting requireFine to false), i get actual coordinates(i havnt plotted them onto a map so i cant say how accurate they are).
My usage:
-GPS settings enabled on phone, check
-Manifest permissions(course & fine), check
-calling beginUpdates in onResume(calling endUpdates immediately after i get the coordinates), check
-checking if hasLocationEnabled before getting coordinates, check
Heyo, I'm having an issue where the GPS location is only being updated very occasionally, despite the fact that I have explicitly defined it as 0.5s (500ms).
My Code:
public class MainActivity extends AppCompatActivity {
public SimpleLocation location;
@Override
protected void onCreate(Bundle savedInstanceState) {
Context context = this;
boolean requireFine = false;
boolean passiveMode = false;
long updateInterval = 500;
boolean requireNew = true;
new SimpleLocation(context, requireFine, passiveMode, updateInterval, requireNew);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
location = new SimpleLocation(this); // Initialise
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(this); // Open settings if the user hasn't put in location permissions.
}
location.beginUpdates();
TextView main = (TextView) findViewById(R.id.multitext);
main.setText("Epoch_ms, lat, long\n");
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() { // Loop forever with 1000ms delay
handler.postDelayed(this, 1000);
SimpleLocation.Point position = location.getPosition();
Log.d("Debug", "Running run");
main.append(((System.currentTimeMillis()) + "," + String.valueOf(position) + ";" + "\n"));
}},1000);
}
}
I'd expect it to output a different value every time it loops (as it should have updated at least twice by then) but it never seems to. It only prints the same value over and over again, however, it is a valid value. I have tried this both in my house, running, as well as in a car, with the same results. It seems if I leave it for a bit, then open the app, it's happy to grab my location, but doesn't update it as I move...
I'm testing it on an OPPO Reno Z (CPH1979) on ColorOS 11.1, and I've confirmed the app has all of the permissions granted, and have tried with both Course and fine, and both with requireNew=true and false.
Many thanks,
GhostDog98
Hi, I implemented everything according to the docs, but it's not working in Google Pixel 3 real device (not emulator)
I've checked :
location.hasLocationEnabled
is true
beginUpdate
called correctlysetListener
, but onPositionChanged
never triggeredSimpleLocation(this, true, false, 500, true)
beginUpdate
, still gave 0.0 & 0.0If I compile the same code to API 29 Emulator, everything working well.
The device's GPS sensor is not broken, because any other maps apps are still working fine.
Do you have any idea, what I need to check or fix?
If I use this constructor:
public SimpleLocation(final Context context, final boolean requireFine, final boolean passive, final long interval, final boolean requireNewLocation) {...}
Passing true to requireNewLocation I can't get a location and onLocationChanged is never called.
But using works perfectly:
public SimpleLocation(final Context context, final boolean requireFine, final boolean passive, final long interval) {
this(context, requireFine, passive, interval, false);
}
EDIT:
Well, not that perfectly in a Samsung Galaxy S4 mini
EDIT 2:
I realized that it's reaching the catch inside this function, but I can't check the error (Maybe I'll have to run the source):
private Location getCachedPosition() {
if (mCachedPosition != null) {
return mCachedPosition;
}
else {
try {
return mLocationManager.getLastKnownLocation(getProviderName());
}
catch (Exception e) {
return null;
}
}
}
Maybe a bug?
Thanks!
Hello, is there a UTC time in a GPS signal? Can you extract it for using? I work with lon lat and UTC timestamp.
How can i get the Accuracy value of the location?
Here is exemple code:
location = new SimpleLocation(this);
// if we can't access the location yet
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(this);
}
location.beginUpdates();
location.setListener(new SimpleLocation.Listener() {
public void onPositionChanged() {
Log.d("Location", location.getLatitude()+":"+location.getLongitude()+":"+location.getAltitude());
}
});
When I open emulator and change Latitude or Longitude first time it fires listener but then it does not.
Hi
thanks for your Java class, After implementing code from your class i get Location is=0.0,Latitude=0.0
my code here
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.distance_find);
if (findComponentID()) {
getToolBar();
getDrawerList();
location = new SimpleLocation(this);
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(this);
}
imgBtnGetLocation.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View v) {
getCurrentLocation();
}
});
}
}
@OverRide
protected void onResume() {
super.onResume();
location.beginUpdates();
}
@Override
protected void onPause() {
location.endUpdates();
super.onPause();
}
private void getCurrentLocation() {
final double latitude = location.getLatitude();
final double longitude = location.getLongitude();
Log.d("Testing", "Location is=" + "Latitude=" + latitude + "Longitude=" + longitude);
txtViwMyLocation.setText("Latitude=" + latitude + "\n" + "Longitude=" + longitude);
}
If the location is previously on while running the application first time, it's picking the latitude and longitude.Then if I close the app and turn off the location, while opening the app for the second time its navigating to settings to turn on location but after location is on it is unable to pick the latitude and longitude. I am getting 0.0 for both.
Hello Marco, I recently went through your wonderful library but I couldn't really figure out the difference between the above mentioned two.
Can we really rely on your library to find out the location in case of real Life and Death situations?
Hello All,
Your library is very good but in this I have found one issue and if possible please fix it as soon as possible .
Problem Statement : when I am connected to internet , it give me right location but when I am not offline (i.e not connected to Internet) then this library return me some past location which is random .
Please follow the steps to re-generate the issue :
1.) Connect to internet from one location and get lat & long
2.) Now Disconnect your internet from same position , now you will get some past location i.e lat & long .
So please check it and let me know , if you get some thing .
Thanks
I have incorporated the same code as given in the documentation. It is working perfectly fine in most of the android versions, however it isn't working in android IcecreamSandwich. I am using mobile micromax A210. Please help!
Hi. I am getting the error Cannot resolve method 'getTimestampInMilliseconds()
when trying to call that method. The same error occurred for the getElapsedTimeInNanoseconds()
method. Any idea? getSpeed()
, getPosition()
, and other methods work fine.
import im.delight.android.location.SimpleLocation;
public class MainActivity extends AppCompatActivity {
private SimpleLocation mLocation;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLocation = new SimpleLocation(this);
mLocation.setBlurRadius(5000);
if (!mLocation.hasLocationEnabled()) {
SimpleLocation.openSettings(this);
}
final long timestampInMilliseconds = mLocation.getTimestampInMilliseconds();
final long elapsedTimeInNanoseconds = mLocation.getElapsedTimeInNanoseconds();
}
@Override
protected void onResume() {
super.onResume();
mLocation.beginUpdates();
}
@Override
protected void onPause() {
mLocation.endUpdates();
super.onPause();
}
}
i'm trying to install on android studio,
i've put it on build.gradle,
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "veeklab.desg"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.github.delight-im:Android-SimpleLocation:v1.0.1'
}
after i ran the build, this error shown
Error:(26, 13) Failed to resolve: com.github.delight-im:Android-SimpleLocation:v1.0.1
<a href="openFile:/home/vickydasta/research/mobile/Desg/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Hello mwaclawek,
I am very grateful that you have made this wonderful library available to everyone and it is pretty awesome.
But currently im facing some issues with getting the current location, as the old known location is only getting updated most of the times... And in many devices im only getting (0,0) coordinates...
Is there any way I can correct it and make it update the location to the current one every-time asked for and eliminate the (0,0) coordinate results?...
I really need your help and I shall always be grateful to you for the same... Please help...
I am developing an app where the location must be invisible to the user.
The idea is that if the user has GPS enabled, the coordinates go with FINE, and if only network enabled, the coordinates are sent with COARSE, is there any way to achieve that?
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.