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

JPEG byte array values not as expected for JPEG
Settle FPS in the drawing of image and thus acheive smooth motion on the app screen
Facebook Single-Sign on is not working
Secure Element tutorial error
HttpURLConnection cipher error : Could not find cipher suite
Progress dialog not showing
Android mediaplayer mute
Android application AndroidRuntime
Android UnknownHostException when using HttpGet
Catch Javascript onclick events in an HTML page hosted in a WebView
How can I use ORMLite with SQLCipher together in Android?
Setting a Unique ID for Android Phone
How to get Purchased state of a managed productid in android in appbilling?
How do i adb pull ALL files of a folder present in SD Card
How to get String length [closed]
Good design pattern for dialogs in Android

Categories

HOME
turing-machines
hyperlink
cheerio
linkedin
fpga
interface
themes
requirements
entity-framework-core
cq5
zip
recordrtc
bing-maps
sendgrid-api-v3
spin
jquery-ui-sortable
pcl-crypto
categorical-data
alamofire
line
openbugs
shared-libraries
gource
3nf
bitnami
alpacajs
microsoft-dynamics-nav
feathersjs
easyphp
oledb
breadth-first-search
springfox
gulp-watch
object-storage
zxing
displaytag
perlbrew
game-theory
google-earth
dst
record
dumpbin
git-squash
laravel-eloquent
least-squares
fiware-cygnus
typesafe-config
kill
android-softkeyboard
android-ibeacon
xmldocument
opennms
facebook-pixel
dtsearch
mongotemplate
page-replacement
shinobi
bootstrap-tags-input
reachability
usart
latin
google-cloud-console
windows-azure-queues
respondcms
omniauth-facebook
stream-processing
tracker-enabled-dbcontext
boost-serialization
fuzzywuzzy
character-replacement
opl
r-package
opserver
doctype
skspritenode
snackbar
j-security-check
packet-sniffers
sql-scripts
teaspoon
appserver
paw
linkedin-jsapi
trdion2011
named-parameters
jquery-slider
extjs2
workitem
scmmanager
actiondispatch
traceability
device-width
joomla3.1
patricia-trie
pstack
multiplexing
floating-point-exceptions
virtualpathprovider
node-redis
role
cuteeditor
msr
socketserver
nhprof
metaweblog
dot-emacs
build-environment
filesystemobject
cuda.net
complex-event-processing
fail-fast-fail-early
change-management
wspbuilder

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