android-location

getLastKnownLocation() returns null [closed]

微笑、不失礼 提交于 2019-11-26 08:38:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I have read a lot of Q&As on this topic here on SO but I have to say that none of them works. My problem is that, even though I have GPS enabled, I cannot get a location unless I open Google Maps and get my location and then go back to the app, which is definitely not an option for the users. I have the

Get the distance between two locations in android?

人盡茶涼 提交于 2019-11-26 08:12:59
问题 i need to get distance between two location, but i need to get distance like blue line in the picture. I try next: public double getDistance(LatLng LatLng1, LatLng LatLng2) { double distance = 0; Location locationA = new Location(\"A\"); locationA.setLatitude(LatLng1.latitude); locationA.setLongitude(LatLng1.longitude); Location locationB = new Location(\"B\"); locationB.setLatitude(LatLng2.latitude); locationB.setLongitude(LatLng2.longitude); distance = locationA.distanceTo(locationB);

How to get the current location latitude and longitude in android

心已入冬 提交于 2019-11-26 05:49:43
问题 In my application, I get the current location\'s latitude and longitude when application is open, but not when the application is closed. I am using Service class to get the current location latitude and longitude in my application. Please tell me how to get the current location latitude and longitude even when application is closed 回答1: Before couple of months, I created GPSTracker library to help me to get GPS locations. In case you need to view GPSTracker > getLocation Demo AndroidManifest

Enabling Location mode High Accuracy or Battery saving, programmatically, without user needing to visit Settings

旧巷老猫 提交于 2019-11-26 05:24:00
问题 Why i ask this: (also the reason for trying it in an app) It happens when we use Google Maps in Lollipop . Even if the Location is disabled, it is turned on, in high accuracy mode after user\'s input from the Maps app, without having to visit Settings. A similar functionality can be achieved for enabling Bluetooth, where the action is initiated in my app; user needs to make a choice but user is not redirected to Settings, using: startActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)

How to get the current location latitude and longitude in android

社会主义新天地 提交于 2019-11-26 02:58:30
In my application, I get the current location's latitude and longitude when application is open, but not when the application is closed. I am using Service class to get the current location latitude and longitude in my application. Please tell me how to get the current location latitude and longitude even when application is closed Before couple of months, I created GPSTracker library to help me to get GPS locations. In case you need to view GPSTracker > getLocation Demo AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android

Background service with location listener in android

馋奶兔 提交于 2019-11-26 00:57:09
问题 I am creating a background service that will run in its own process. It should allow me to listen if the device location has changed. I should be able to change criteria like the distance moved before notifying the UI. How can I do the same? I have a little knowledge of service and LocationListener implementations. Any tutorials around the net would be appreciated. I got one back-link from stack overflow, but I didn\'t understand much of it. 回答1: First you need to create a Service . In that

Good way of getting the user&#39;s location in Android

谁说我不能喝 提交于 2019-11-26 00:49:22
问题 The problem: Getting the user\'s current location within a threshold ASAP and at the same time conserve battery. Why the problem is a problem: First off, android has two providers; network and GPS. Sometimes network is better and sometimes the GPS is better. By \"better\" I mean speed vs. accuracy ratio. I\'m willing to sacrifice a few meters in accuracy if I can get the location almost instant and without turning on the GPS. Secondly, if you request updates for location changes nothing is

How to get current location in Android [duplicate]

微笑、不失礼 提交于 2019-11-25 23:39:57
问题 This question already has an answer here: How do I get the current GPS location programmatically in Android? 22 answers I\'m having troubles of getting my current position coordinates using the NETWORK provider of android location system. Already read a lot of tutorials and implemented 4 or 5 existing classes to my project and all of them are giving me the last coordinates but not the current ones. I\'m pretty sure that the problem is something fundamental that I am missing but I am not able