android-location

Get the distance between two locations in android?

只谈情不闲聊 提交于 2019-11-26 22:10:44
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); return distance; } but i get red line distance. Use the Google Maps Directions API . You'll need to request the

isProviderEnabled(LocationManager.NETWORK_PROVIDER) return false

若如初见. 提交于 2019-11-26 22:00:48
问题 I am using NETWORK_PROVIDER to get latitude and longitude of the place. I'v already check the setting in the "location & security" and enable "use wireless networks". But "isProviderEnabled(LocationManager.NETWORK_PROVIDER)" always return false . Can anyone help me? Thank you in advance! Here is my code : LocationManager locManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean isEnableGPS=locManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isEnableNTW

LocationClient doesn't give callback when screen light goes off but my WakefulThread is running flawlessly as expected

眉间皱痕 提交于 2019-11-26 19:50:33
问题 To retrieve fused location in background, I have created a library which is very similar to cwac-locpoll library created by Commonsguy. Inside PollerThread , I am trying to connect, request and retrieve the locations using LocationClient . I am able to get connected by receiving callback on onConnected method but I am not able to get callback on onLocationChanged method.so my onTimeout thread executes as per decided interval. NOTE: This issue happens only when screen light goes off.otherwise

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

倖福魔咒の 提交于 2019-11-26 17:21:13
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)); which could be found on BluetoothAdapter , now we know there is no LocationAdapter, so i looked

Error adding geofences in Android (status code 1000)

╄→гoц情女王★ 提交于 2019-11-26 16:48:56
问题 I am getting an error in the onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) callback with statusCode = 1000 . I have my GPS enabled and my WiFi. I also have Google Play Services and I am able to track my location and request updates. Why am I not able to add geofences? I am not able to add geofences even from the documentation sample app. I get the following Toast message: "Add Geofences: Failure, error code 1000 GeofenceRequestIds=[1,2,1,2]" From the documentation

Get current latitude and longitude in the string

纵然是瞬间 提交于 2019-11-26 14:51:53
问题 I am trying to get latitude and longitude but sometime network is available but I am not getting value of latitude and longitude . I am using MyLocationListener class and put condition all but some time value is not getting. protected void showCurrentLocation() { Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { counter++; latitude=location.getLatitude(); longitude=location.getLongitude(); altitude=location.getAltitude(); } }

Why is FusedLocationApi.getLastLocation null

强颜欢笑 提交于 2019-11-26 13:45:50
问题 I am trying to get location by using FusedLocationApi.getLastLocation and I've got the location permissions in the manifest file: <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> However, I am getting null when I request the location from the system. I was just testing turning off and on location services so it may be related to that (of course, it's ON when I'm trying this). But even after

Fused Location Provider unexpected behavior

若如初见. 提交于 2019-11-26 12:39:51
问题 this is how I register my app to receive location updates: mLocationRequest = LocationRequest.create(); mLocationRequest.setInterval(Consts.ONE_MINUTE * 10); mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); mLocationRequest.setFastestInterval(Consts.ONE_MINUTE); Builder builder = new GoogleApiClient.Builder(context); builder.addApi(ActivityRecognition.API); mGoogleApiClient = builder.addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build();

Android Location Manager, Get GPS location ,if no GPS then get to Network Provider location

巧了我就是萌 提交于 2019-11-26 12:37:36
问题 I am using this given below code to get locations: public Location getLocation() { try { mLocationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE); // getting GPS status boolean isGPSEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); // getting network status boolean isNetworkEnabled = mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { // no network provider is enabled } else { // First

ACCESS_COARSE_LOCATION permission gives a cell tower precision on Android

淺唱寂寞╮ 提交于 2019-11-26 10:58:40
问题 I am making some tests with the requestLocationUpdates() function from the FusedLocationApi . I am using the PRIORITY_BALANCED_POWER_ACCURACY. A city block precision is fine for me. When I request the ACCESS_FINE_LOCATION permission, I get around a 100m precision which is great with GPS off. As I do not need a GPS precision but a city block precision, I would like to request only the ACCESS_COARSE_LOCATION permission. However when I request the ACCESS_COARSE_LOCATION permission, I get a 2 km