Comments (3)
- Did you follow all steps from the README?
- Can you log something in the
onPositionChanged
callback? - Can you show your call to the
SimpleLocation
constructor?
from android-simplelocation.
-
yes I have followed the readme.Please go through the following code.
my activity code :public class MainActivity extends AppCompatActivity {Button btn_location;
private SimpleLocation location;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);btn_location = (Button) findViewById(R.id.btn_location); // 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(MainActivity.this); } btn_location.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!location.hasLocationEnabled()) { // ask the user to enable location access SimpleLocation.openSettings(MainActivity.this); } final double latitude = location.getLatitude(); final double longitude = location.getLongitude(); if (latitude != 0.0 && longitude != 0.0) { Log.d("LOCATION", "LATITUDE :" + latitude); Log.d("LOCATION", "LONGITUDE :" + longitude); Toast.makeText(MainActivity.this, "Latitude is :" + latitude + " longitude is :" + longitude, Toast.LENGTH_SHORT).show(); }else{ Log.d("LOCATION", "LATITUDE :" + latitude); Log.d("LOCATION", "LONGITUDE :" + longitude); location.beginUpdates(); } } });
}
@OverRide
protected void onResume() {
super.onResume();
if (!location.hasLocationEnabled()) {
// ask the user to enable location access
SimpleLocation.openSettings(this);
}// make the device update its location location.beginUpdates();
}
@OverRide
protected void onPause() {
// stop location updates (saves battery)
location.endUpdates();
super.onPause();
}
}
from android-simplelocation.
First, you should be able to safely remove the if (!location.hasLocationEnabled())
branch and its contents from onResume
because you have it in onCreate
already.
Second, the additional call to location.beginUpdates()
in the OnClickListener
in onCreate
is probably superfluous.
Otherwise, this looks good. But why donβt you implement the onPositionChanged
callback as shown in the README and try to log something there. That way, you would see if and when location updates are available.
Last but not least, you should try the extended arguments of the constructor, again, as shown in the README. For example, try replacing
location = new SimpleLocation(this);
with
location = new SimpleLocation(this, true, false, 5 * 1000, true);
and see if that helps. It should attempt to update the location every 5 seconds.
from android-simplelocation.
Related Issues (20)
- Location not updated in background service HOT 6
- lat, lng is 0 HOT 3
- Location is not giving updated latitude and longitude HOT 1
- Accuracy HOT 1
- I've just copy+paste the code but returns 0.0 HOT 1
- calculateDistance not found HOT 1
- Cannot resolve HOT 5
- Lat : 0, Lon : 0 HOT 3
- Location tracking failed on background HOT 1
- Speed is 0.0 and interval is not decreased HOT 1
- precise only upto 3 digits of longitude & lattitude HOT 5
- GPS UTC time? HOT 1
- Is this library working on background process HOT 1
- Works only first time then It does not work HOT 1
- Not working in Android 10 real device HOT 3
- passiveMode, what does it mean ? HOT 1
- Cannot resolve method 'getTimestampInMilliseconds()' HOT 3
- Received first coordinates (not 0, 0), but values did not update afterward. HOT 12
- Only Updating very occasionally, despite update interval being set to 500 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-simplelocation.