Android-SimpleLocation
Android-SimpleLocation copied to clipboard
Lat : 0, Lon : 0
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();
}
} `
Well, your implementation looks good. It seems you have indeed read the documentation well and checked other issues for a solution. Thank you!
-
Did you try this on a real device or on the emulator? If it’s the latter, try a real device instead.
-
In the
onClickcallback of yourView.OnClickListener, the calllocation.beginUpdates();is definitely redundant. You can safely remove that.
-
Copy your
Log.icall and paste it at the end of theonPositionChangedcallback ofSimpleLocation.Listener. Of course, it might make sense to change the message string as well. Otherwise, you don’t see when new location data becomes available. -
Try changing the second argument of the constructor from
truetofalseto switch between GPS location and network location.
Does that help?
In general, this is unfortunately quite a common problem, but still one that can easily be solved, I’d say:
- https://github.com/delight-im/Android-SimpleLocation/issues/24
- https://github.com/delight-im/Android-SimpleLocation/issues/22
- https://github.com/delight-im/Android-SimpleLocation/issues/20
- https://github.com/delight-im/Android-SimpleLocation/issues/15
- https://github.com/delight-im/Android-SimpleLocation/issues/11
- https://github.com/delight-im/Android-SimpleLocation/issues/9
- https://github.com/delight-im/Android-SimpleLocation/issues/3
- https://github.com/delight-im/Android-SimpleLocation/issues/2
- https://github.com/delight-im/Android-SimpleLocation/issues/1
If you target a newer Android platform, you should ask a user for access to their location explicitly. https://developer.android.com/training/permissions/requesting
when i am overriding the onResume method my UI get stuck and black screen occur any suggestions