I have picked up Google mock location provider from here: http://developer.android.com/training/location/location-testing.html. I verified that it is indeed providing mock locations by opening Google Maps. The location tracker in maps keeps moving somewhere around Google's office, indicating it is responding to the mock locations. BUT, when I open my own app I do not get the mock locations. I continue to get the real locations. Do I have to make any changes to my app to get mock locations? One more bizarre thing is that even after I shut down the mock location provider , Google Maps continues to receive the mock locations. Only when I restart the phone it goes back to receiving real locations. Any ideas how to proceed? Any other options to test mock locations?
Tested on MotoG (4.4.2)
Edit:
Test code : https://github.com/nutiteq/hellomap3d/blob/master/HelloMap3D/src/com/nutiteq/hellomap/HelloMap3DActivity.java
This is just the nutiteq sample app. App works fine, but continues to receive real locations even when mock provider is running.
There is the standard requestLocationUpdates call and then an implementation of onLocationChanged callback.
OK, a bit too hasty placing a bounty. Sorted this by using the same Location Provider "gps" both in the LocationProvider app and in my app.
Related
I've been working on an app that needs to be location-aware, and I've noticed that there are two (or more) methods of receiving location: with Google Play services (as seen here developer.android.com/training/location/retrieve-current.html#GetLocation) and with Location Manager, Providers etc. (as seen here http://www.vogella.com/tutorials/AndroidLocationAPI/article.html#locationapi_criteria).
What is the difference between these methods (if there is any)? Which one is more accurate?
edit: ok, I see that I sent the wrong link on the first thing. Won't this code (http://developer.android.com/training/location/receive-location-updates.html) give me location updates? Generally, what's the most accurate way to get my location?
The one with the GPS is accurate and that which is based on Network is not. Google Play Service use FUSE api to get the GPS location first, if the location is found (that's great), otherwise it will try to get location fix from Network Tower. In Short the one with GPS is accurate
The first method provides the details of LastKnownLocation. ie. the last location received from GPS or network provider when you or other apps accessed the location services. After that there are chances you moved a lot and it need not be your current location. So if You are planning to create an application that requires accurate location tracing, You should fetch the location as in the "Vogella" method. If the current location is unavailable, you can try using the last known location (As a plan B :-)).
I newbie in location and trying make service to show my current location and another one location saved previously. And what the difference of using LocationListener vs LocationClient?
The LocationListener connects to the LocationManager and retrieves your location. This worked and works fine.
The LocationClient is a new way to implement this while some of the rest gets deprecated. It features more functions.
Both methods actually works.
Location Manager was introduced in Android SDK and can be used as a feature of android.
Location Client is something that's part of Google Play SDK and is introduced in the recent Google IO 2013.
You can understand that since LocationClient is the latest, it is more efficient in getting the location with minimal energy(battery drain) with greater accuracy.
Reasons to use LOCATIONCLIENT because:
The location update behavior is very abnormal and wont work as you expect. i.e. The location updates get stuck when switching networks. (It keeps giving you some old location)
The location client wont work on modified android versions of the android OS, as it requires Google play services.
Location Client might be good on the battery of the phone but it won't be good with giving you timely accurate location updates.
I recommend good old Location Manager as I don't find location client reliable at all.
Note : There is no point of saving battery if you are not even getting your current location in a location based application.
I am writing an app which needs to get any fresh location. Accuracy does not metter. My app will mainly be used in buildings, so I am using Network location provider as a main location source.
I have troubles on some devices as follows:
My code can't access any location. But when I start Google Maps on the same device - it shows correct location. I switch back to my program and it does not see any location again.
My code does roughly the following:
Check if Network location provider is available with code below:
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
If network provider is enabled - requirest single location update:
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Code also starts Timer for 5 seconds. If code does not get requested location update during 5 seconds, then timer is iterating throuhg all available providers trying to get last known location and pick up the best one:
Location location = locationManager.getLastKnownLocation(provider);
The result of all these moves is that network provider is On, but code does not get any updates. Timer starts, loops through all providers and all of them does not have any last known location. getLastKnownLocation method returns null for all of them. The most strage thing is that Google Maps got correct location just a few seconds before this. I've rebooted device with no effect.
I examined best practices of getting location here. They seem to use the same approch as I currently do. Are there any tricks I am missing?
This problem occur in some devices the solution is try to get location from GPS if fails then get location from WIFI device
Im writing an android aplication in which is required the actual location of the user, but I'm having trouble acquiring that location.
I'm using a LocationListener to listen for the location update, via Wifi (NETWORK_PROVIDER).
The problem is I don't get an update, and I imagine it only happens when I change network. If I don't get updates, I can use lastKnowLocation but it does not provide me with the actual user's location.
Is there a way to force a location update, via NETWORK_PROVIDER?
Cheers
Even better, I suggest you look at the new Location APIs in Google Play Services.
There's a training class for them as well.
I use network provider to get location in Android application. Sometimes I found the location would not be changed even after I arrived at a new place. At the same time, I found the locations were changed in Google Map. So I quit and restarted my application, and the locations wasn't changed either. But after a long period, or I reboot the phone, I could see the new location.
Does any one know what's the reason ? I have used getLastKnownLocation() to get the latest location in my application.
Update:
When this problem happened, I found the cellid and LAC was changed while the location wasn't changed. So it's very strange. I think Google Map may use cellid & LAC to get the location directly, so it can get the correct location.
More update:
When this problem happened, I used the cellid and LAC to get the location via HTTP POST request from Google server. This location was correct.
BTW, I found my question was like this question: Android network location takes hours to update location
I wouldn't trust getLastKnownLocation(). In my experience this isn't reliable.
You'd be better off requesting location callbacks using LocationManager.requestLocationUpdates(). If you only need the location once you can then unregister for the callbacks using LocationManager.removeUpdates() after that. If your application needs to be notified when the location changes then you can register for callbacks with a reasonable minium-time and/or minimum-distance parameter (based on whatever your application requires.