Android Question Getting position from wifi or other means

Discussion in 'Android Questions' started by JMB, Aug 16, 2019.

  1. JMB

    JMB Active Member Licensed 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?


  2. Brandsum

    Brandsum Active Member Licensed User

    Use fused location provider
    Xicu, JMB and emexes like this.
  3. JMB

    JMB Active Member Licensed User

    I shall check that out. Thank you.
  4. emexes

    emexes Well-Known Member Licensed User

    Probably. But could also be this:

    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:
    Last edited: Aug 16, 2019
  5. JMB

    JMB Active Member Licensed 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.

  6. emexes

    emexes Well-Known Member Licensed User


    Although on mobile devices, it might only pin you down as close as the head office of your mobile service provider, but... from a standing start, that's a heck of a lot better than defaulting to (0, 0).
    f0raster0 likes this.
  7. JMB

    JMB Active Member Licensed 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.
  8. JMB

    JMB Active Member Licensed 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...
  9. f0raster0

    f0raster0 Active Member Licensed User

    Your position can be tracked even if your smarphone is turned off.
  10. f0raster0

    f0raster0 Active Member Licensed User

    You need to walk..staying in just one place just using gps will not help
  11. emexes

    emexes Well-Known Member Licensed 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.
  12. JMB

    JMB Active Member Licensed 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.
    f0raster0 likes this.
  13. emexes

    emexes Well-Known Member Licensed User

    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.

    f0raster0 likes this.
  14. emexes

    emexes Well-Known Member Licensed User

    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.

    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:
  15. f0raster0

    f0raster0 Active Member Licensed User

    Ok I worked with GPSs over 500 in mining..but Ok :) ahah maybe smarphone' GPS are better ahah!! anyway agreed with you :)
  16. f0raster0

    f0raster0 Active Member Licensed User

    using the others sensors and antennas of your smartphone..
  17. emexes

    emexes Well-Known Member Licensed User

    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.
    f0raster0 likes this.
  18. JMB

    JMB Active Member Licensed User

    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) :)
    emexes likes this.
  19. BillMeyer

    BillMeyer Well-Known Member Licensed User


    Eish (South African Term) - please start by reading this

    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...
    Xicu, José J. Aguilar and JMB like this.
  20. JMB

    JMB Active Member Licensed 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.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice