delight-im / Android-SimpleLocation

Utility class for easy access to the device location on Android
Apache License 2.0
200 stars 75 forks source link

I am get only Location is=0.0,Latitude=0.0 i am using emulator #2

Closed RajeshRajendiran closed 9 years ago

RajeshRajendiran commented 9 years ago

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

}
ocram commented 9 years ago

Thanks for your question!

Please test the code on a real device to rule out the emulator as the cause for this problem.

Did you add one of the permissions to your app? Otherwise, your code looks okay.

On the emulator, you have to specifically enable location support and you have to set a faked location or mock location. If that's really what you want to do, you may read more here: http://stackoverflow.com/questions/2279647/how-to-emulate-gps-location-in-the-android-emulator

RajeshRajendiran commented 9 years ago

Thanks for your support dude, I checked real device worked perfectly