android-location

NullpointerException when calling getSystemService(Context.LOCATION_SERVICE) and onLocationChanged not called

房东的猫 提交于 2019-12-10 14:21:39
问题 I am trying to create a background service that updates the current gps position. I am getting a NullPointerException at line LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); HomeActivity launches a service startService(new Intent(getApplicationContext(), ForHire.class)); Service (ForHire) creates a TimerTask Updates public class ForHire extends Service { ... private Timer getUpdatesNow = new Timer(); private Updates updates = new Updates(getUpdatesNow);

[Android-Location]Can not get Longitude and Latitude from LocationManager

柔情痞子 提交于 2019-12-10 12:02:16
问题 I used LocationManager to get user address by "Longitude" and "Latitude" but when i call location.getLongitude() and location.getLatitude(), it return 0 back to me. I manage to Google but have nobody meet my issue. Mr.Jeremy Edwards suggest me that: Make sure that network based location is enabled in the phone's settings. You can detect this situation and prompt the user to enable it if you really need it. I believe this is the line of code to launch this activity. I do that but it can help.

How to get users Location through GPS with Target API 23 and higher

一曲冷凌霜 提交于 2019-12-10 11:08:46
问题 I am trying to implement a GPStracker in my project which I want to use to get users lat, long and post code. I am following this tutorial; http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/, however, I can't seem to get the code working and after hours trying and researching I am not sure what I should do. I am fairly new to Android so I am probably making a silly mistake. When I follow the guide as shown on the website posted I get an error message on my code saying:

Is Fused Location Provider good choice?

与世无争的帅哥 提交于 2019-12-10 04:33:46
问题 I am developing an application where I want to use Fused Location Provider. But I have some doubts, and couple of questions. When GPS is off and I set priority to HIGH, does that mean that the GPS will be automatically turned on, or not? Can I set UpdateLocation with Fused provider with HIGH priority on demand to save battery at least a little bit? How can I know what Fused provider is using (is it a GPS or a network provider)? And finally Is Fused provider really the best choice for android

Geocoder returns an address with zero length

三世轮回 提交于 2019-12-10 04:15:21
问题 Geocoder was working fine until today. It started to return String with 0 length. Note: This is not a duplicate of Geocoder threads, i used intent service and AsyncTask to get it before starting the thread(and AsyncTask approach was working fine over 8 months), checked this code and new code from Google with FusedLocationProviderClient(this is offical code) it also returns string with zero length.This link from official Android page shows how to get it with intent service. I get full address

Android: Get current location in China

守給你的承諾、 提交于 2019-12-10 00:40:39
问题 I need to get current location in China but current location manager is not working in china.Its not showing latitude and longitude. Please tell me how can I get this? Many Thanks 回答1: Fact 1: All Google services are blocked in China. Fact 2: Although it gives a feeling that AOSP is nothing to do with Google, it's really not. The truth is that once you used NETWORK_PROVIDER to get a location, a message was send to Google location server to check out the location, and returned the location

Android Geofence not triggers once location OFF and ON again [duplicate]

会有一股神秘感。 提交于 2019-12-09 07:11:32
问题 This question already has answers here : How to check if Location Services are enabled? (18 answers) Closed 4 years ago . I am using Android Geofencing API.After add geofence it works fine when location is ON.But If I OFF location and ON again,afterwards Geofencing not triggers when enter or exit.I have tested on my Moto G with Android 5.0.2 device. Is it Geofence will expire If location is off? I have seen on Android document as, In case network location provider is disabled by the user, the

Samsung Note 2 can't reach onLocationChanged()

守給你的承諾、 提交于 2019-12-08 21:40:41
问题 It works on most devices except Galaxy Note 2. It connects to Google Client, but can't reach onLocationChanged() that implements LocationListener . Anyone has any idea what it causes and why only on this device? @Override public void onLocationChanged(Location location) { mLastLocation = location; if (mLastLocation != null) { lat = mLastLocation.getLatitude(); lng = mLastLocation.getLongitude(); Toast.makeText(getApplicationContext(), String.valueOf(lat) + "/" + String.valueOf(lng), Toast

SecurityException when calling getLastKnownLocation

孤者浪人 提交于 2019-12-08 16:01:03
问题 We've been getting reports of crashes on some devices when a user opens an Activity that calls the location manager's getLastKnownLocation method. We've requested all the required permissions in our application manifest: <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Here is the stack trace: java.lang.RuntimeException: Unable to resume activity {com.projectname/com.projectname.ui

Android GPS Location Update Method does not work in OnCreate of Map activity

牧云@^-^@ 提交于 2019-12-08 11:08:46
问题 I am facing a problem with the LocationManager class: I want to update my current location in onCreate() of a class extended from MapActivity : LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); MyLocationListener lcs = new MyLocationListener(); lcs.onLocationChanged(lm.getLastKnownLocation(LocationManager.GPS_PROVIDER)); whereas getLastKnownLocation() returns the location but inaccurate, I want to call LocationManager.requestLocationUpdates() which returns