My Android app requires the user to enter the current location either by manually searching or by pressing a button to automatically detect the location. I've done the search part using PlaceAutocompleteFragment, but for the detection part I'm confused between the above mentioned classes. To my knowledge, PlaceDetectionClient provides details about the actual building, like a business, and FusedLocationProviderClient uses various sensors to detect the location. Aside from the building detail thing, what's the difference between the two? Which one is more reliable and easier to implement?
It depends on what do you need. If you need user location in your app, better way is to rely on latitude and longitude, so I believe it is better use from FusedLocation which provides exactly what you need.
PlaceDetectionClient is API to detect places where user is nearby i.e check-in feature in current place. I am not sure it is what you really need.
Related
I am working on an app that needs to access GPS status, and obtain data about visible satellites like Constellation type, is it used in position fix, Elevation egress etc. I've been using Android Framework Location API that has classes in android.location package for that, especially GnssStauts. Now, I see that Google recommends switching to using Location Services API from Google Play services because it does a lot of things instead of us (Geofencing, Activity Recognition...), and is more energy efficient and I understand that, I have started using it for getting user location. But, I cannot find out how to use it for more complex needs, like getting GPS satellites data, like I described in the beginning. Am I missing something very obvious here, or Google still didn't cover that type of use cases with new Location Services API (but forgot to mention that anywhere in documentation), so for that cases we should still stick to good old android.location framework?
THe Location Services API are an attempt to not use GPS, but try to calculate from additional sources like wifi, cellular signals, etc to save from having to power on the GPS chip. Generally its more accurate than network but less than GPS. (Technically I believe it can be forced to use just GPS, but it isn't the normal way of using it). If you need actual GPS data about satellites, it isn't going to help you. If you need to run on non-Google approved devices, it isn't going to help you (unless they pirate Google Play Services). For your usecase, I would skip it and just use the built in location code.
EDIT: As Francky Vincent said, I see that price depending on distance is not advisable. I have 4 parts but only 3 are the prices depending heavily on the distance (and planning to change it later). But, I still need to get current location as I have 'x.x KM from you'.
A little bit of intro:
When I was around somewhere with low coverage, I open the Grab app and able to get my current location, even though will take too much time. My own app have no problem with location but at the same location, it will get the last known location - and I don't want that since one of my app feature is the price is according to the distance between current location and target.
For the codes, I just using the examples provided for Fused Location by Google in Github and seems like it's not enough? My aim is to get current location instead of last known - just like the Grab app.
Is that possible using Fused Location? Or did the example provided can achieve what I want but I missed something important?
I referred to this question but still got clueless. Really new with this feature.
The strategies that I can come up is:
Start app
Check permission
Request permission
Get current location
Save the latitude and longitude in SharedPreference
Stop getting location
Please help. Thank you!
Just simple as that.I dont want to find new coordinates every 10 minutes or meters.I just want to click a button and get my coordinates for this exact moment/place where i am.Every tutorial i've seen its old.New android versions require permissions to use GPS or Network.I am trying to implement those but nothing seems to work.
Any solutions?
Thanks in advance
I just want to click a button and get my coordinates for this exact moment/place where i am
That's not possible in general. The device may not know the user's "coordinates for this exact moment/place". You are welcome to call getLastKnownLocation() on LocationManager, or perform equivalent sorts of lookups with Play Services' fused location provider, but they may return null. Usually, to find out where the user is, you request location updates, then react when you get a location fix.
Every tutorial i've seen its old
These sample apps (for the fused location provider) and this sample app (for LocationManager), from my book, should be up to date.
New android versions require permissions to use GPS or Network
All Android versions require permissions to determine the user's location, for blindingly obvious privacy reasons. This has been the case since before Android 1.0, and it should remain the case for the foreseeable future.
I am trying to implement those but nothing seems to work
Then ask a fresh Stack Overflow question, where you provide a minimal, complete, and verifiable example demonstrating your problems.
I'm trying to build an app using the GoogleMaps API and the user's location (once-off) and trying to find out how best to approach this but it seems like the approach the Stack Overflow answers take is very different to the approach the Android Developer site takes.
Basically the SO answers suggest subscribing to service that gives you location updates which you handle in a callback, whether you want the location once (like me) or actually plan to use the updated positions. (Post 1, Post 2, both highly up-voted)
However the Android dev site says you should connect a LocationClient and then just call getLastLocation() as you need it, which removes a bunch of the switching between sync and async coding elements.
So, I'm still confused as to what the "best-practice" way of doing this is and to why the Android dev site doesn't agree with the high-scoring answers here.
Both the posts you've linked to are quite old (3 and 4 years old).
Android has come a long way in that time, and now we have an excellent Location API as part of the Google Play Services that you should use to get the user's location. This would be the current best practice.
Android provides 2 ways to get GPS location. LocationManager and LocationClient. LocationManager has a request callback type and a get last known location. LocationManager has inherent issues. Some phones dont report back the callback at all, nor do they return back the Location from get last known location. LocationManager also uses a lot more battery.
LocationClient is the new and best way currently. They also use much lesser battery.
Would it be possible to make an Android application that works based on location, for example when you get to work the app might turn off WiFi or Bluetooth or change any other system settings in order to save battery or something?
The app would require the user to enter in locations where they want the app to begin working, like their address, and when the phone sees that they have arrived at this location it will start working. I want to do this but I don't know where to start.
I already have some android app development experience.
Yes absolutely this is possible. I have worked on approx three application with same concept.
You need to create a center point and define a radius for the same.
Then you need to calculate the distance of you current location with that particular center point and if your distance is less than or equal to radius, trigger to switch on the services you want.
In android you can use
LocationManager class
For collecting the data. If you want some more help I can provide the same too.
I've played around with a concept like this on the Windows Phone for a while, and I think this would work for Android too.
Basically, you'd use the GPS of the device to detect your location, and then compare this to the locations saved by the user. If the location comes within range of a saved setting, perform an action.
GPS usage however drains battery, so you'd have to experiment a bit with making this an efficient method.
Have you tried GeoFencing, its really cool. It lets you define a center point, and a radius. Once the user enters this radius you get callback or a pendingIntent. You can do what you want in your callback.
You can get addresses of your customers and build geofence around their locations.
Edit :
If you choose to not use GeoFenceing (for what ever reason), note that LocationManager is highly buggy and unstable on most mobile phones (Samsung).
Instead use LocationClient, which takes care of all the crap LocationManager leaves with us to deal with and provides location faster, lesser battery and customized accuracy.
Edit :
If anyone tries to convince you otherwise, check this out. A video from google developers and their talk about why LocationManager sucks, and why they knew and helped us figure out the value Sensors add to the entire solution.
Edit : Design of your solution
You need 2 geofences
1) Outer, you can hard code this to a imaginary 500 m from office. From then on you can start looking for wifizones
2) Once a wifizone is found, save the gps and the distance from his address point. That is your inner radius.
1 Geofence is defined by your install, 2nd geofence is defined by your runtime.
2nd Geofence and be used henceforth to disable GPS (only incase you decide to use LocationManager). If not you wont need this, LocationClient will do what it does best.