android


Unable to get current location Longitude and Latitude using GPS


I am try to use my GPS to get the Longitude and Latitude of my current location. But i am getting nothing, I am also not getting any type of errors or logcat. Here is my code that I am using
public class MainActivity extends Activity implements LocationListener {
protected LocationManager locationManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
#Override
public void onLocationChanged(Location location) {
Log.e("--", String.valueOf(location.getLatitude()));
Log.e("--", String.valueOf(location.getLongitude()));
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.e("--", String.valueOf(status));
}
#Override
public void onProviderEnabled(String provider) {
Log.e("--", String.valueOf(provider));
}
#Override
public void onProviderDisabled(String provider) {
Log.e("--", String.valueOf(provider));
}
}
Thank you in advance
I had the same issue I drop my idea of using specific provider as on one of my phone's GPS is not working fine. I used Criteria to let the system choose it for me if it is best else it will choose another one. so when my GPS is no working properly(works fine on one phone and not on other) it choose network location provide.
locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
locationManager.requestLocationUpdates(provider,0,0, this);
Location location = locationManager.getLastKnownLocation(provider);
if(location != null )
{
onLocationChanged(location);
}
hopes this helps

Related Links

Testing Android In App Billing purchases
AlarmManager Not Firing Regularly
Getting Incorrect current GPS location in FusedLocationProviderApi
android get current playing audio stream type
Xamarin Viewpager's fragment disappears after activity is changed?
Detecting document contours from camera preview
Android - AsyncTask error when ListView empty?
Why is my download button in phonegap app not working?
Should FirebaseDatabase.getInstance() be used sparingly?
How to auto refresh data displayed in my Android Activity every second
Media recorder stopped notification
How to realize a Swipe to submit on Android?
How can I find documentation for android:listSeparatorTextViewStyle?
emergency: update 1 fragment from viewpager having two fragments
Word has not enough space in single line
Socket IO Socket won't connect on Motorola device

Categories

HOME
android
c++11
datastore
graphics
requirements
shiro
nuget
alsa
maxscript
missing-data
nstableheaderview
arangodb
mql5
32bit-64bit
google-form
pybossa
renjin
3nf
gruntfile
azure-iot-hub
microsoft-dynamics-nav
identity-management
oledb
sar
cgbitmapcontext
angular-routing
parcelable
event-store
exploit
appirater
ntp
complex-numbers
jmockit
simplecv
gnat-gps
yowsup
searchkit
hivemq
zoomify
openalpr
loading
spring-mvc-test
knime
jide
openal
linter
gitlist
sonarlint-eclipse
wcftestclient
tinymce-3
java-bytecode-asm
java-6
truezip
boo
objectscript
mathcad
android-instrumentation
polyline
taocp
autosar
reporting-services-2012
xcode-server
adafruit
dotnetnuke-7
drawstring
riot
beanstalk
concept-insights
rasterize
maybe
terracotta
dllimport
wiredep
google-books
rubaxa-sortable
.bash-profile
lasso
keyup
beatsmusic
android-vibration
browserify-shim
iso-prolog
insight.database
tinyxml
multiautocompletetextview
ecslidingviewcontroller
light
gtm-oauth2
jeromq
hidapi
rolify
flex++
time.h
jquery-1.9
preload
device-width
idn
midlet
jquery-blockui
cross-database
box2d-iphone
automationelement
listactivity
cloudfiles
updatesourcetrigger
easyb
jqueryform
build-environment
application-planning
firefox-3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App