why need to wait some second after enable GPS,to work? - android

I am making a small app, when the user clicks the button the app gets the users location and opens Google maps.
The problem is, if the users mobile doesn't have GPS enabled , then enables it and clicks the button again, this method will return null:
location = service.getLastKnownLocation(provider);
When I wait after enabling GPS and then click the button, the method will work correctly and return the location.
How can I solve this problem?

why need to wait some second after enable GPS,to work?
It's because when you enable GPS it'll fix position of Satellite and based on that you'll able to get Location.

It is obviously a default behaviour, when you stop GPS and start it again, there is a small gap between start and stop, at that point, GPS will do its task, to get satellite data and after that it will provide you location. If we want to drive fast then we must need to start from 1st gear, same behaviour GPS doing.

As the answers mention above, the device will get the location after a while. If you are in the middle of a flow, you can show a ProgressSpinner and poll getLastKnownLocation() for x seconds to get a location.

If you hadn't used GooglePlayServicesClient try this to get user location.
It is the fastest way to get current lat long.
For reference and code use the following link.
http://developer.android.com/training/location/retrieve-current.html
Hop i helped you.

Related

Android Fake GPS location apps do not work anymore

I used to work with this application:
https://play.google.com/store/apps/details?id=com.fakegps.mock&hl=en
And before this with this one:
https://play.google.com/store/apps/details?id=com.incorporateapps.fakegps.fre&hl=en
Am working on a LG G3 and a Nexus 5, but in the last couple of days, the fake location doesn't work as it should.
It doesn't always modify my location and sets in where I want. Or many times, it sets my location where I want for a couple of seconds and then resets to my real location. I'm working on a travel app, and this made it very simple to simulate trips and locations.
Is there any other fake location app that actually works how it should?
Or is there any other way to set the location of my phone, while the app is running?
EDIT: YES! MOCK LOCATIONS is ON.
Like i said: It DOES change my location, to the mock location I want, but it jumps back to my REAL location, after a couple of seconds. Depending, sometimes, it stays for minutes on the mock location, but then jumps for 1 second on my real location, and then goes back :)
Now I know this, cause I log all the locations that I find, even more, draws the path, and I have lines that jump back to my Real location and then continue
PICTURE: Pink = how it should be.
Green = locations that I get and the path. As you can see, each a couple of locations that I get, it jumps back to my location
https://www.dropbox.com/s/sszzrvhnwlq2bxr/Screenshot%202015-09-10%2015.47.20.png?dl=0
If mocked location seems to jump to real one during simulation, try to turn off wifi based locations (Settings / Location / Mode --> Device only).
Make sure you have Allow Mock Location turned on in phone's Developer Options and try this app: https://play.google.com/store/apps/details?id=fr.dvilleneuve.lockito&hl=en
I'm using it when working on Geofencing and works great.
I managed to fix this problem by disabling the "Fused Location" service on my phone. I used the Disable Service application which requires root privileges to run. After disabling the "Fused Location" service I stopped teleporting to my real location.
In Settings -> General -> Location -> Mode
I switched it from Battery Saving to High accuracy and then the mock location app started working.
Note, you also need to set your preferred Mock Location app in Developer Options, but even after doing that my app was showing my true location instead of the mocked location - now it's working like a champ!

Is there any way to get the current location of a user and display it on a map without the need of GPS?

I want an image of my user's location to show up on a map every time he/she logs in - and to only update the location after the user exits the app then reopens it. While he is in the page with the map the location should stay constant.
Can I achieve this without GPS? I haven't been able to find much about it online.
Thanks in advance for any insight
This is a similar post where it's explained how to use network instead of GPS
If you have the users IP addresses then you should be able to get the location of the IP by using a service (e.g. https://www.iplocation.net/). But this location is of course not very accurate especially for example when users are located for example in country A but use a VPN in country B (then the location inside country B will be shown to you) but it may be suitable for your scenario.
I think Skyhook is what you are looking for.

Android Tracking App - check if someone is getting closer or distancing from specific point

I created an android app, which stores user's home location and count distance between home and his/her actual location, in a Service class.
Now I would like to programme feature that would decide based on counted distance, if a user is:
at home
away
getting closer
distancing from home
This should be similar to Google Now, that can predict that you are for example going home. If someone had some examples, I would be sooo grateful
To implement such kinda work, you need to implement GeoFence in your android app.
GeoFence gives you idea about user entered/exited from a defined area. If you set home location as base location and radius to 500m then it gives you entered callback you are within 500m of your home.
When you go away 500m from your home location then it gives you exited callback. To know about whether you are home location then at a interval of few minutes you can poll GPS coordinates then can identify whether you are at your home location.
https://developer.android.com/reference/com/google/android/gms/location/Geofence.html

android check if GPS already has a fix

i have an app that takes the user exact GPS location and save it to a database when he presses a button.
i need his exact location(i.e location that is Fixed with GPS)
i used onLocationChanged() and GPS_EVENT_FIRST_FIX, but the problem was if the user was standing still and already had a fix, then he pressed a button, the app would wait as it neither of the above will launch.
and i was wondering if there was any way i can check if the GPS already has a fix on the device's location.

How to update the location after the particular time in android?

I am working on location based application for android .In that i want to check GPS is enabled in my mobile or not.If enabled means find the location based on GPS otherwise i want to check after five minutes again disabled means i want to find the location using network provider
Please any one give me Idea for that with some sample code.
Start here. I am not using a timer like you want so here is a post where it is being used as you are describing.

Categories

Resources