Some Bits: Nelson's log

2 posts in March 2019

CA-1: Congressional vs State Senate district

We have a special election for California State Senate in District 1 this year. Judging by past elections this district is roughly 65% Republican. I was confused because California’s National Congressional District 1 looks like a very similar part of California, the northeastern rural part. But it was only 55% Republican last year. Why the big difference?

So I made a map of the difference between the two districts. Turns out the Congressional district includes a big part of the northern central valley including Red Bluff, Chico, and Oroville (outlined in blue). (Also a tiny bit of rural area north of Roseville.) The State Senate district instead includes a chunk of the middle Sierra including Truckee and Placerville. I don’t have demographic data in front of me but it seems plausible that explains the political difference. Static map below, there’s also a slippy map online.

Details: I used 2017 data from the US census, The files are cb_2017_06_sldu_500k and cb_2017_us_cd115_500k. I then did some QGIS munging (finally, easy basemaps!) to calculate the simplified symmetric difference and display it reasonably.

Mapbox GL Native telemetry

I finally closed the loop on a long-standing problem we have had with our Wanderings location tracker. We wrote our code to be very low impact; it uses the Significant Location Changes API on iOS to track your movements in a very passive way. But our app was causing the phone to use as much as 100 MBytes/day when running in the background! All that bandwidth was accounted to “Time & Location” in iOS itself, not our app.

Much sleuthing later we narrowed the problem down to Mapbox Metrics, their telemetry service. You can see some discussion in this bug report, but the behavior is expected, not a bug. And somewhat unique to our app. If we turn off telemetry our usage goes down to < 1MB / day of data.

By default telemetry is turned on if you use Mapbox native in your app. And it listens to location updates your app gets. If your app gets a notification the person has moved, Mapbox then requests fine grained location updates for a short period of time. (5 meter movements for 5 minutes, I believe.)

There’s nothing nefarious or dumb here. The location telemetry is a disclosed part of the product and the code is open source. They have appropriate privacy protections. And it’s a reasonable form of telemetry for most apps. I imagine most Mapbox apps have the map front and center as part of the UI with location tracking already enabled, so Mapbox’s telemetry requests don’t really generate any more traffic. Unfortunately our app is just unusual in wanting low impact background updates only, not a good match for the telemetry behavior. Fortunately our users can turn off the telemetry tracking if they want. (In fact, Mapbox requires that apps provide a telemetry opt-out option for users.)

The other confusing piece of this is why does location tracking use so much network bandwidth, and why is it attributed to iOS itself and not our app? Only Apple really knows, but I have some guesses. Phones almost never use an honest GPS signal to track location; mostly location is tracked by reference to nearby Wifi and cellular signals. My guess is every time the phone wants to know its position the iOS location daemon itself makes a TCP/IP request to some Apple server to do a lookup. (I’ve definitely noticed that my location tracking goes way worse when I have cellular data turned off, say when traveling in Europe.) That data usage is significant if you are tracking location in a fine-grained way. And since the request comes from iOS and not the app, the bandwidth is accounted to iOS itself.

While I’m guessing, I think in practice “significant location change” means “moved into range of a new cell tower”. My guess is those location updates come “for free” because the cellular chip already has to do a bunch of work for tower handoffs. Based on observation, moving in range of a new Wifi network is not enough to trigger the location update.