Android Question Getting position from wifi or other means

JMB

Active Member
Licensed User
Longtime User
Hi there,

I've been playing around with the GPS tutorials, and I note that when I use Google Maps, it gets a position really quickly even though the GPS has no lock - I've used various different apps to show that the GPS has no position but Google Maps comes up with a pretty accurate position anyway.

I presume this is using Wifi information - is this correct? And is there any way in B4A to access this position data while waiting for a GPS signal?

Thanks,

JMB
 

emexes

Expert
Licensed User
I presume this is using Wifi information - is this correct?
Probably. But could also be this:

https://tools.keycdn.com/geo

And is there any way in B4A to access this position data while waiting for a GPS signal?
There are services that return that info via JSON over HTTP, but I am having trouble finding the forum posts about that. Or I might be conflating it with the related task of turning a longitude-latitude into an address, eg:

https://www.geocode.farm/v3/json/reverse/?lat=51.503844&lon=-0.127652
 
Last edited:
Upvote 0

JMB

Active Member
Licensed User
Longtime User
I tried the Fused Location Provider, but it came up with a Problem parsing package error. I updated the Android version in the Manifest to 26, and I am wondering if this code no longer works.

JMB
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
It just seems odd that the GPS programs take so long to get a fix, but when you enable location services in Google Maps, it gets a position virtually instantly - and to a high degree of accuracy. I can't figure out where it is getting its location data from, because it seems VERY accurate.
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
I am in a hotel at the moment on the 5th floor with my device next to the window, and it's taking ages...
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Your position can be tracked even if your smarphone is turned off.
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
I am in a hotel at the moment on the 5th floor with my device next to the window, and it's taking ages...
You need to walk..staying in just one place just using gps will not help
 
Upvote 0

emexes

Expert
Licensed User
You need to walk..staying in just one place just using gps will not help
Staying on one place is fine by GPS. Your current problem will most likely be that your GPS is only receiving signals from a small part of the sky, slightly larger than you can see, and that either:

1/ not enough satellites are in view to get a fix (you need at least four) (ok... some GPS's will work with three, but at decreased accuracy), and/or

2/ the satellites are not spaced far-enough apart to get acceptable accuracy

Or it could be that the window glass is blocking the signal, eg, additives for tinting or strengthening. Train windows are notorious for this.

If you go for a walk outside, with a clear view of the sky, then the GPS should sort itself out within 5 minutes.
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
Thank you for that. I'll check that out... Makes debugging a GPS application an interesting experience!

I'm still confused as to how Google maps gets its location so fast... Without moving.
 
Upvote 0

emexes

Expert
Licensed User
Your position can be tracked even if your smarphone is turned off.
Another good reason for avoiding smarphones ;-)

but more seriously: my initial reaction was wtf?!?!? but then I closely reread your statement and realised that you didn't specify that the tracking need be by the smartphone.

I agree with: Your position can often be tracked by other means even if your smartphone is turned off.

 
Upvote 0

emexes

Expert
Licensed User
I'm still confused as to how Google maps gets its location so fast...
Probably by surveying local wifi SSID's, and then refer to their (Google, Apple, whoever) list of which SSID's correlate to which locations. So, depending on how the hotel has organised its wifi access points, they can quite possibly pin you down to within 20 metres, eg, east side floor 17 of hotel at <address> within a floor or two.

Bear in mind that they do not need to be able to connect to the wifi networks, they just need to see the broadcast information akin to what you see in your list of visible networks when searching for a network to connect to.

Without moving.
Moving only required for bearing (direction of movement). Position and speed can be obtained even if stationary.

On a vaguely-related topic: there are many fixed-location GPS's around the world used for measuring atmospheric effects on GPS signals in order to generate correction parameters that can be used to enhance mobile GPS accuracy, eg: http://rtcm-ntrip.org/home.html
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Staying on one place is fine by GPS. Your current problem will most likely be that your GPS is only receiving signals from a small part of the sky, slightly larger than you can see, and that either:

1/ not enough satellites are in view to get a fix (you need at least four) (ok... some GPS's will work with three, but at decreased accuracy), and/or

2/ the satellites are not spaced far-enough apart to get acceptable accuracy

Or it could be that the window glass is blocking the signal, eg, additives for tinting or strengthening. Train windows are notorious for this.

If you go for a walk outside, with a clear view of the sky, then the GPS should sort itself out within 5 minutes.
Ok I worked with GPSs over 500 in mining..but Ok :) ahah maybe smarphone' GPS are better ahah!! anyway agreed with you :)
 
Upvote 0

emexes

Expert
Licensed User
staying in just one place just using gps will not help
Staying in one place is fine by GPS.
but Ok :) ahah maybe smarphone' GPS are better
Look at it from this perspective: you are moving ~300 m/s due to earth rotation, and the satellites are moving ~4000 m/s in orbit, and consequently the distances between you and the satellites are constantly changing... fractionally offsetting that movement by walking at a brisk 2 m/s under consistent sky will make negligible difference to reception.

To me, it is akin to magic that the whole thing works at all. Bit like helicopters - the engine starts, the blades spin, it floats up into the air... vs gut-feel reasoning that predicts it should screw itself into the ground.
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
To me, it is akin to magic that the whole thing works at all. Bit like helicopters - the engine starts, the blades spin, it floats up into the air... vs gut-feel reasoning that predicts it should screw itself into the ground.

An interesting analogy, given that I actually fly helicopters for a living! We usually sacrifice a goat to the Gods of Aviation before we go flying - that's how we keep airborne (or so I'm told) :)
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
B4Xer's,

Eish (South African Term) - please start by reading this https://en.wikipedia.org/wiki/Location-based_service

Your "smart" device has 3 locations stored or used at any given time. These are:

1. GPS
2. LBS (Uses WiFi, Cell Towers, IP address)
3. Last known location

So your location is always known (this is how GSM/LTE functions with several things like RSSI, Satellites, IP Address etc coming into play to provide the data)
This information can be obtained by your GPS, by Trilateration (Info Here) or your last known IP address and is stored on your device (last known location) and if your location services are on then it is passed to Google for all sorts of strange things.

When you have an app that needs location for what ever reason (and you are using Fused Location Provider for example) you can look at whatever is available and start your process on that while your app connects to GPS and gets a Lat/Lon reading (heading/bearing, speed, altitude is also available) to give a more accurate picture of what you require.

Given all this, bear in mind that GPS is battery intensive and at times (especially travelling in urban areas - speed slower) it will suffice to use LBS (WiFi or Cell Towers) to navigate and by so doing save battery power and only occasionally call on GPS for a more accurate update.

Then, after all this is considered, where does the Haversine Formula play a part here ??

PS. Google have several API's that assist with all these issues.


As @Peter Simpson Says Enjoy...
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
Bill, thanks for that. I had started to look at the Android Documentation but that's a really useful explanation.

I presume that the Fused Location Provider (which I have now got to work) takes all of this into consideration.

JMB
 
Upvote 0
Top