Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lat : 0, Lon : 0 #27

Closed
SezerFidanci opened this issue Apr 26, 2018 · 3 comments
Closed

Lat : 0, Lon : 0 #27

SezerFidanci opened this issue Apr 26, 2018 · 3 comments
Labels

Comments

@SezerFidanci
Copy link

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();
}

}
`

@ocram ocram added the question label Apr 26, 2018
@ocram
Copy link
Contributor

ocram commented Apr 26, 2018

Well, your implementation looks good. It seems you have indeed read the documentation well and checked other issues for a solution. Thank you!

  1. Did you try this on a real device or on the emulator? If it’s the latter, try a real device instead.

  2. In the onClick callback of your View.OnClickListener, the call

    location.beginUpdates();

    is definitely redundant. You can safely remove that.

  3. Copy your Log.i call and paste it at the end of the onPositionChanged callback of SimpleLocation.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.

  4. Try changing the second argument of the constructor from true to false to 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:

@spidgorny
Copy link

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

@anmol-Git
Copy link

when i am overriding the onResume method my UI get stuck and black screen occur any suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants