Get the distance between two locations in android?

Use the Google Maps Directions API. You’ll need to request the directions over HTTP. You can do this directly from Android, or via your own server. For example, directions from Montreal to Toronto: GET http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false You’ll end up with some JSON. In routes[].legs[].distance, you’ll get an object like this: “legs” : [ { “distance” : … Read more

Comparing two locations using their Longitude and Latitude

You actually need to implement a function called distance that will calculate the distance between two locations. Calculating the distance between two locations is one possible way of comparing the longitude and latitude values. An example of comparing them: @Override public void onLocationChanged(Location location) { double lat2 = location.getLatitude(); double lng2 = location.getLongitude(); // lat1 … Read more

Determining the speed of a vehicle using GPS in android

for more information onCalculate Speed from GPS Location Change in Android Mobile Device view this link Mainly there are two ways to calculate the speed from mobile phone. Calculate speed from Accelerometer Calculate speed from GPS Technology Unlike Accelerometer from GPS Technology if you’re going to calculate speed you must enable data connection and GPS … Read more

Error adding geofences in Android (status code 1000)

You get GEOFENCE_NOT_AVAILABLE (code ‘1000’) when user disagrees to “Use Google’ location services” in Settings->Location->Mode: To fix it: go to Settings->Location->Mode set “Device only (Use GPS to determine your location)” set any other option to get the popup (e.g. “High accuracy (Use GPS, Wi-Fi and mobile networks to determine location”) dialog “”Use Google’ location services” … Read more

Why is FusedLocationApi.getLastLocation null

The fused location provider will only maintain background location if at least one client is connected to it. Now just turning on the location service will not guarantee storing the last known location. Once the first client connects, it will immediately try to get a location. If your activity is the first client to connect … Read more

Finding current location of the user in Android

posting simple solution with code. add permissions inside AndroidManifest.xml file <uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” /> <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” /> if you app is marshmallow compatible then check run time permission. add dependency inside gradle file: compile ‘com.google.android.gms:play-services:9.2.0’ implements this two interface in you activity GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener and create googleapiclient object like this in oncreate: mGoogleApiClient = new GoogleApiClient.Builder(this) … Read more

ACCESS_COARSE_LOCATION permission gives a cell tower precision on Android

This is an interesting problem, and I was under the impression that using ACCESS_COARSE_LOCATION would use WiFi, since that’s what the documentation says. The documentation for ACCESS_COARSE_LOCATION states: Allows an app to access approximate location derived from network location sources such as cell towers and Wi-Fi. So, I put it to the test, and the … Read more

Fused Location Provider unexpected behavior

For the questions specified, 1. is the fused location provider suppose to use GPS at all if it set to receive updates with PRIORITY_BALANCED_POWER_ACCURACY and don’t have any WI-FI or cell towers info ? & 2. if it does, then what am I doing wrong? Apparently no explicitly unique source is specified anywhere within documentation. … Read more