Bug 233095 - www/firefox geolocation no longer working
Summary: www/firefox geolocation no longer working
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-gecko (Nobody)
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2018-11-09 20:59 UTC by J.R. Oldroyd
Modified: 2025-02-23 05:24 UTC (History)
5 users (show)

See Also:
jbeich: maintainer-feedback? (chromium)


Attachments
patch to adjust WiFi scan results (479 bytes, patch)
2025-02-12 17:38 UTC, J.R. Oldroyd
no flags Details | Diff
patch to make geolocation URL use the correct key (595 bytes, patch)
2025-02-12 18:01 UTC, J.R. Oldroyd
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description J.R. Oldroyd 2018-11-09 20:59:37 UTC
The geolocation code in netwerk/wifi/nsWifiScannerFreeBSD.cpp is failing to return lat/lon location.

Repeat by going to:
    http://html5demos.com/geo
Grant it location access permission.  It fails.  It should work and show your lat/lon position.

I wrote the code in nsWifiScannerFreeBSD.cpp back in 2012.  I believe the wifi lookup code itself is still good.  I have verified it is being compiled in (it is, it's in libxul.so).  I have run firefox with debugging enabled and see that the code is still finding the local wifi networks (run firefox with "-MOZ_LOG=timestamp,WifiMonitor:4" to see this).

A manual test of the geolocation API per the instructions here:
    https://developers.google.com/maps/documentation/geolocation/intro
seems to show that the API key we are using has expired and billing needs to be enabled on it.  Firefox appears to be getting the daily usage limit exceeded error.
Comment 1 Jan Beich freebsd_committer freebsd_triage 2018-11-10 00:23:49 UTC
Does geolocation work in www/chromium? That's where the API key originates. Like with SafeBrowsing the quota has to be extended. Unfortunately, I don't know who to contact.
Comment 2 J.R. Oldroyd 2018-11-10 13:06:17 UTC
Just tried it.  No, it fails on www/chromium too.
Comment 3 J.R. Oldroyd 2018-12-19 17:54:22 UTC
According to this page:
    http://www.chromium.org/developers/how-tos/api-keys
We need to enable billing on our Chromium Project page, but the use of the API is then free.
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2020-01-04 19:56:07 UTC
Does this workaround the issue? 

geo.wifi.uri

    https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%

– and if so, is it an _appropriate_ alternative?

(NB the trailing `%`)
Comment 5 Jan Beich freebsd_committer freebsd_triage 2020-01-04 21:43:56 UTC
gecko@ doesn't have Mozilla API key, so bandwidth maybe limited. Open resource://gre/modules/AppConstants.jsm to inspect actual values for various %FOO% strings.
Comment 6 peter.hillerstrom+freebsd 2021-12-11 00:46:58 UTC
For me the percent values are (with part of the Google API key redacted in case it is somehow generated on build):

MOZ_GOOGLE_LOCATION_SERVICE_API_KEY: "AIza...1mp8",
MOZ_MOZILLA_API_KEY: "no-mozilla-api-key",

And the advanced settings have:
geo.provider.network.url	https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_LOCATION_SERVICE_API_KEY%

Google has retired the v2 API on 26th of May 2021:
https://developers.google.com/maps/documentation/javascript/v2tov3

So maybe that is the reason it does not work?
I would really much like this to be fixed, as I do a geolocation based service.
Comment 7 J.R. Oldroyd 2025-02-12 17:37:14 UTC
I did some debugging of this.

There appear to be two problems.

1. The FreeBSD wifi scan code uses the isr_rssi value directly.  This results in incorrect values.  It needs to adjust for the isr_noise noise level.  I am attaching a patch to correct this.

2. Secondly, I cannot get it to work directly with the default Google geolocation URL [1].  However, if I change the URL (in about:config geo.provider.network.url) to a proxy script on my own server, then call that same Google geolocation URL from that script it works just fine (with the patch).  To debug this, I want to enable logging (I've tried using [2] and also using about:logger) to see what's going on, but the log files are created but remain empty.  Anyone have suggestions for how to get the log to show?

[1] https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_LOCATION_SERVICE_API_KEY%

[2] MOZ_LOG_FILE="/tmp/log" MOZ_LOG="timestamp,sync,gWifiMonitorLog:5" firefox
Comment 8 J.R. Oldroyd 2025-02-12 17:38:36 UTC
Created attachment 257440 [details]
patch to adjust WiFi scan results
Comment 9 J.R. Oldroyd 2025-02-12 17:43:33 UTC
Ah... additional info.

Perhaps the second problem is that the value %GOOGLE_LOCATION_SERVICE_API_KEY% is not being substituted with a valid key.  If I put the actual key in geo.provider.network.url, it works.
Comment 10 J.R. Oldroyd 2025-02-12 17:49:55 UTC
Ahhh...

The key is defined in MOZ_GOOGLE_LOCATION_API_KEY.
But the default for geo.provider.network.url has %GOOGLE_LOCATION_API_KEY%.

Adding the "MOZ_" part into the URL makes it work.
Comment 11 J.R. Oldroyd 2025-02-12 17:53:13 UTC
Sorry, above should read GOOGLE_LOCATION_SERVICE_API_KEY and MOZ_GOOGLE_LOCATION_SERVICE_API_KEY.
Comment 12 J.R. Oldroyd 2025-02-12 18:01:25 UTC
Created attachment 257442 [details]
patch to make geolocation URL use the correct key
Comment 13 J.R. Oldroyd 2025-02-12 18:54:51 UTC
Hmm.  That second patch for the key may not be needed.  It is sending the correct key when I use my proxy script URL with the ?key=%GOOGLE_LOCATION_SERVICE_API_KEY%.

I am noticing though, that while it is mostly working, it is also sometimes returning an error about billing needed to be enabled:

    {
      "error": {
        "code": 403,
        "message": "PERMISSION_DENIED: You must enable Billing on the Google Cloud Project",
        "errors": [
          {
            "message": "PERMISSION_DENIED: You must enable Billing on the Google Cloud Project",
            "domain": "geolocation",
            "reason": "forbidden"
          }
        ]
      }
    }

Wait a short while, and it works again:

    {
      "location": {
        "lat": 0.123456,
        "lng": 0.654321
      },
      "accuracy": 13.936
    }
Comment 14 J.R. Oldroyd 2025-02-15 23:21:53 UTC
This is now working well using my own Google API key and the patch from Feb 12th.

What's the possibility of obtaining a FreeBSD Google API key with billing enabled for the Geolocation API for this to work generally?

Right now, Googl's API pricing is that the first $200 of API calls are free, then it is $5 for the next 100,000 calls.

From 2025/03/01 that changes to the first 10,000 calls are free then $5 for the next 100,000 and $4 for the next 400,000 calls.  A budget of just $13.50/mo would get us 5,000,000 API calls.