ways of getting my location on android - android

This may be a kinda odd question but I am new at Android development and I'm having trouble to learn how to retrieve the user's location to my application. I have looked for this topic but I just can't find a statisfying answer.
To get the user location I have found two ways:
http://developer.android.com/training/location/retrieve-current.html . This one is using what I think is the new Google Services release which uses a LocationClient to connect to Google Services and retrieve the location.
http://developer.android.com/guide/topics/location/strategies.html . The other one is using the android.location class and a LocationManager to retrieve the location.
The thing is that I don't get the difference between using one way or the other, which one is better??
And another question is that in the second way you can specify which location provider you want to use, if the GPS provider or the Network provider and in the first one you can't, but in the first paragraph it says that it uses the location sensors that are currently active for the device. Does this mean that I don't have to worry about choosing between both services??
I am using Android Studio and I have set up the new Google Services release, I just need to know the pros and cons between both ways to know which one to use and to begin learning.
Thanks!!

As stated in the second link:
The Google Location Services API, part of Google Play Services, provides a more powerful, high-level framework that automatically handles location providers, user movement, and location accuracy. It also handles location update scheduling based on power consumption parameters you provide. In most cases, you'll get better battery performance, as well as more appropriate accuracy, by using the Location Services API.
I would highly recommend you to watch the last I/O video to get a simple explanation from Reto Meier about the new Location Provider: http://youtu.be/GcNNx2zdXN4?t=14m29s (I suggest you to watch the entire clip btw, it's inspiring).

Related

Android's most accurate Location API

In order to work, my app requires a location API.
I intend use the Mapbox platform to customize its design (since Google Maps
does not provide this level of customization, as far as I am concerned).
Documentation says that we should use Google Play API when building location
apps:
The Google Play services location APIs are preferred over the Android
framework location APIs (android.location) as a way of adding
location awareness to your app. If you are currently using the Android
framework location APIs, you are strongly encouraged to switch to the
Google Play services location APIs as soon as possible.
My question is:
Is Google Play API the most efficient API when it comes to GPS accuracy?
Or should I use the LocationManager and LocationListener way of doing it?
I need accuracy. Which one should I use?
Thanks.
In android also there are three types of location :
GPS_PROVIDER
NETWORK_PROVIDER
PASSIVE_PROVIDER
So, as per my coding experience I came to know that if you use :
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, new MyLocationListener());
you will get precision upto 14+ decimal places.
But if you use fusion of them like this :
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, my_google_listener);
you will get precision upto 6 to 7 decimal places. try it !!! reference
But note few things here that, GPS Provider takes time to fetch location while Google Location is much faster as it gets data from API call to its google server database.
GPS works offline while google provider gets the location via mobile or wifi data.
Use FusedLocationProviderApi and set LocationRequest priority to PRIORITY_HIGH_ACCURACY
This is newest API for accurate location fetch and google suggest to use the same.
Check Accuracy details here.
Basically Google play services API has intelligence to get accurate location by fusing GPS+NetworkProvider+passive providers.
FusedLocationProviderApi is deprecated.You should use FusedLocationProviderClient and you should add ACCESS_FINE_LOCATION permission,not ACCESS_COARSE_LOCATION to get the most accurate location.
And read this article to understand why FusedLocationProviderClient is the best solution.
In my experience, the Google Services Location API are preferable to use in following aspects:
they deal with user settings, choosing the best available location provider. If you choose to work with LocationManager directly, your code will need to handle that.
you might expect to get a better location with less power usage, as Google regularly updates their algorithms for determining location using WiFi, cell towers, etc.
In my experience, using Google Services, location with accuracy sufficient for a mapping application (that is some tens meters) in many cases does not require GPS data. That might also be the case with FusedLocationProvider, though, maybe with an exception for the battery usage numbers.
To conclude, if you don't have arguments to NOT use Google Services (such as - you target a country where they are not available, or want to distribute via alternative markets) you should use their Location API.

I am trying to pull an active user's location at any given time

I would like to find an API that allows me to pull a client's current location. I know Google Places and FourSquare have API's available. Basically, I want it to run at all times, as I am eventually going to create a dating app that allows you to see who is at a current bar/restaurant/social setting at any given time.
The fetch for the current location will obviously have to be running at all times, and there are considerations of using too many client resources. With that being said, what are some of my options?
Yes, you can use the Google Places API for this: PlaceDetectionApi.getCurrentPlace(). See https://developers.google.com/places/android-api/current-place (and the Getting Started guide).

Using Google Maps location without Activity

I have a service which receives locations through registering a LocationManager.requestLocationUpdates.
But there have been some issues on some phones.
When battery runs low, the network location provider stops sending location fixes (this problem is addressed in this SO question). It's not a only a problem with my app but also the other apps just stop receiving locations.
Even when the phone is recharged the problem persists until the full reboot.
However, I found out (and someone also mentioned it in the SO question above) that Google Maps still keeps receiving location updates - when I open Google Maps app it shows the correct location and updates.
So I was thinking about a workaround of using locations from Google Maps API. I have absolutely no experience with the Maps API, but it seems that it needs a proper GUI (Activity) application to be used with. Or am I wrong? Is there a possibility to use Google Maps API to receive locations even within the Service?
Given some extensive testing from a reliable source, I believe that you might want to consider using the FusedLocationProvider supplied with Google Play Services. It seems to take the headache out of choosing the appropriate power criteria and so on.
Be aware that this will require that the user must have Google Play installed on their device, so Kindles and the like will be out of the picture. It also requires a minimum of Android 2.2.
Some more information about the location services provided by Google Play Services can be found here.

How does google maps get location on android device?

I am an android developer and have been using it for a while to develop context-aware apps. Location is one of the most important thing for context aware and accuracy of that location is very important.
I know how to get location from GPS using LocationManager... I know how to develop apps using Google maps on android... and also how to display user on the map.. etc. But my friends have found out that when they went to a foreign country for a conference, their location from LocationManager is very inaccurate compare to google maps.
They used my app (not released yet.. ) which I get my location from LocationManager and I registered for GPS and Network provider. If I plot the location that the phone gives me on a map... it's very inaccurate... some times it thinks the user is in Barcelona even though they are at a conference in USA.
Also since the conference was indoor, the GPS wouldn't have helped a lot because it would've had hard time finding a fix.
Does google maps on android get their location similar to how google tells the android developers to get the location... from LocationManager and register for onLocationChanged location listener? If it does... how come theirs is more accurate... how do they filter any outliers? or are they using any internal services to get even more accurate location which maybe google assume that if the developer get that accurate location they could misuse it?
Any ideas or comments??
This code is written by Reto Meier, Tech Lead for Android Developer Relations, who wrote the book on Android App development. Also, that was published in Google IO conference in 2011 as I remember. This is the closest to what is used in Google Places. And it works smart anyway ;)
https://code.google.com/p/android-protips-location/

Android - getLocation()

I have developed an application for my company to track the work done by our agency people and also their location to capture the work places. As we don't want the agency people to browse other website, with the help of network providers we have restricted other websites and allowed only two URL where we run the webservice to store the information captured to the database. But since Android talks to google to get the location we also need map the maps.googleapis.com but when we tried it's not working. Can anyone tell me which URL we should map/whitelist to allow my application to access the google. Thanks
i would think u would get coordinates regardless of internet connectivity. of course i could be wrong. are you sure you added permissions for location services in the manifest. i know i have tested gps apps without internet enabled (emulator though). of course the map wont load but coords should be able to be read from the gps receiver.
If you're talking about getting your current location, then you should use LocationManager(search on SO or google, there are lots of posts about it). Otherweise you can take a look at the Developer Guide for Google Maps, but I'm not sure if Android even uses the same API, though.
Or you can only retrieve the coordinates from the devices to your database/server and you'll have the map and with the coordinates you'll know where are they. That would not need a map in the application, and no need for whitelisting the urls. This is another idea, though.

Categories

Resources