How to group latitude/longitude points that are ‘close’ to each other?

There are a number of ways of determining the distance between two points, but for plotting points on a 2-D graph you probably want the Euclidean distance. If (x1, y1) represents your first point and (x2, y2) represents your second, the distance is d = sqrt( (x2-x1)^2 + (y2-y1)^2 ) Regarding grouping, you may want … Read more

Change Location Mode to High Accuracy Programmatically Android

It is possible to get the device’s current location mode since API level 19 (Kitkat): public int getLocationMode(Context context) { return Settings.Secure.getInt(activityUnderTest.getContentResolver(), Settings.Secure.LOCATION_MODE); } These are the possible return values (see here): 0 = LOCATION_MODE_OFF 1 = LOCATION_MODE_SENSORS_ONLY 2 = LOCATION_MODE_BATTERY_SAVING 3 = LOCATION_MODE_HIGH_ACCURACY So you want something like if(getLocationMode(context) == 3) { // do … Read more

How to get Android GPS location

Here’s your problem: int latitude = (int) (location.getLatitude()); int longitude = (int) (location.getLongitude()); Latitude and Longitude are double-values, because they represent the location in degrees. By casting them to int, you’re discarding everything behind the comma, which makes a big difference. See “Decimal Degrees – Wiki”

Google Play Service location API returns wrong location sometimes

The Location that you get from the API will have accuracy in meters. You should also check how old the location is. https://developer.android.com/reference/android/location/Location.html#getAccuracy() https://developer.android.com/reference/android/location/Location.html#getTime() People generally discard the location if accuracy is greater than 50 or 100m. Why this happens? It takes some time for the GPS of the device to find satellites and get … Read more

Android 11 users can’t grant background location permission?

Credits for the answer to @Stephen Ruda I have run into the exact same problem. I agree that this is an issue for any developer who needs background location permission. I would like to add additional notes for other readers: (1) On API 30+ you will first need basic location permissions before asking for background … Read more

Using Google Play Services LocationClient in background service

Full source code for a background service available here: https://gist.github.com/blackcj/20efe2ac885c7297a676 Try adding the super call to your onStartCommand. /** * Keeps the service running even after the app is closed. * */ public int onStartCommand (Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); setUpLocationClientIfNeeded(); if(!mLocationClient.isConnected() || !mLocationClient.isConnecting()) { mLocationClient.connect(); } return START_STICKY; }

Find city name and country from latitude and longitude in Swift

You can use CLGeocoder reverseGeocodeLocation method to fetch a CLPlacemark and get its country and locality properties info. Note that it is an asynchronous method so you will need to add a completion handler to your method when fetching that info: import UIKit import MapKit import PlaygroundSupport PlaygroundPage.current.needsIndefiniteExecution = true extension CLLocation { func fetchCityAndCountry(completion: … Read more

How does it work – requestLocationUpdates() + LocationRequest/Listener

You are implementing LocationListener in your activity MainActivity. The call for concurrent location updates will therefor be like this: mLocationClient.requestLocationUpdates(mLocationRequest, this); Be sure that the LocationListener you’re implementing is from the google api, that is import this: import com.google.android.gms.location.LocationListener; and not this: import android.location.LocationListener; and it should work just fine. It’s also important that the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)