If you drive in Moscow, Istanbul, Tel Aviv or near the Baltic coast, you've probably seen it: your navigator suddenly decides you're on an airport runway, reroutes from there, and you miss your exit. A minute later the dot jumps back.

That's GPS jamming and spoofing, and it's now an everyday thing in a lot of places. A normal navigator can't do anything about it. It has exactly one source of position, and it believes every fix it gets.

I'm a developer and I drive through this daily, so I built a navigator that treats GPS as a witness rather than a boss. It's called Gorizont. Below is how it works, what broke along the way, and the numbers.

The car already knows how fast it's going

The obvious first idea is to integrate the phone's accelerometer. I tried it, and it doesn't work. You integrate twice, the bias error grows quadratically, the phone is tilted in its mount and the car rocks over every bump. It's fine for a short tunnel and useless for ten kilometres.

The car, on the other hand, knows its speed exactly. It's computed from the wheel or gearbox sensors and exposed over standard OBD-II as PID 0D. That's one byte in km/h. It's coarse, but the error doesn't accumulate. Against GPS on a clean signal I measured a ratio of 0.9998 with about 0.4 s of lag.

You read it with a cheap ELM327 adapter (a few dollars). Two things cost me more time than they should have:

  • iPhones can't talk to "classic" Bluetooth ELM327 clones. SPP on iOS is only for MFi-certified hardware, so it has to be Wi-Fi or Bluetooth LE. Say this in big letters to your users, or half your reviews will be "doesn't connect".
  • Send 010D1 instead of 010D. The trailing 1 tells the adapter to expect a single response, so it doesn't wait for a timeout. On cheap clones the polling rate gets noticeably better.

Turns: the eternal gyro-bias problem

Heading is the integral of angular rate around the vertical axis. The phone can sit in the mount at any angle, so I find the vertical from gravity and take the rotation around it.

Gyro noise barely matters. Bias does: a few hundredths of a degree per second become a visibly bent track within minutes. You can only measure bias while the car is standing still, and "standing still" comes from OBD. That's where I hit the least obvious bug of the whole project.

OBD doesn't see speeds below 1–3 km/h, and it answers with a delay. On one drive the car crawled through a U-turn for about eight seconds with the wheel turned. The adapter said "stopped", while the gyro showed a steady 1°/s turn. The first version took that as bias, and every following turn came out wrong.

Now bias is measured in short windows. A window only counts if the readings are flat, agree with their neighbours, and the phone wasn't tilted. The last second before pulling away never counts. A phone held in a hand fails this check, because a hand always moves a little. Engine vibration passes it, because its mean is constant.

Across 14 turns of a city drive, the median turn-angle error is about 1°, and the worst turn is 4.6°. But the absolute heading at the start is unknown, so without a map the whole track is rotated by a constant 6–16°. The map fixes that.

Snapping to roads

Dead reckoning gives the shape of the path; the map says where a car can actually be. A particle filter with 600 hypotheses glues the two together. Every 4 m of travel, each hypothesis is checked against the roads: is it close to a carriageway, and does the direction match?

Three decisions made it work:

  • Each particle carries its own residual gyro bias and speed-scale error, so the filter estimates those too.
  • An off-road particle gets a small weight, not zero. Parking lots, petrol stations and roads missing from OSM are real.
  • If the car is moving faster than 6 m/s and no particle is left on a road, we've lost it. Some particles then get re-seeded onto nearby roads.

The most painful bug lived here. During that re-seeding the heading wasn't constrained, and on a straight motorway the path shape fits both directions equally well. In 21 of 24 replays of one evening drive, the car flipped 180° on the highway and ended up 16 km from the truth. The fix, in spirit, is one line: if the gyro heading is trustworthy, the search keeps it. After that it was 0 flips out of 24, and the end of the same drive was 19 m from the true position.

How far the position drifts once GPS is gone

This is the main test. GPS is on for the first two minutes, then cut, and the error is measured only over the part without GPS. The truth is the real GPS track from the same recording. Each drive is replayed many times, because the particle filter is random: a single run can "prove" anything. On one motorway recording, single runs gave medians anywhere from 17 to 147 m.

The blue line is pure dead reckoning, wheels plus gyro only. Fractions of a degree add up, and by 20 km the position is 3 km off. The red line is the same plus the road map. The error stops growing with distance and stays around 5–30 m. Of that, only 2–3 m is across the road; the rest is along it, so the car is on the right road, slightly ahead or behind.

GPS as a witness

I don't throw GPS away. While it's honest, the app uses it to learn the speed scale and correct the position. The trick is deciding whether it's honest.

Every fix is compared with what the wheels and gyro measured over the same time:

  • GPS jumped 2 km, but the wheels covered 15 m: that's spoofing.
  • GPS says we're standing still while OBD reports 50 km/h: that's spoofing too.
  • Fixes stopped arriving: that's jamming.
  • The fix is slowly being dragged sideways from where we're actually going: suspicious at first, and spoofing if it continues.

GPS screen: spoofing detected

I tested this on recorded drives by injecting each kind of spoof into honest GPS. A gross jump is caught in about 0.3 s, and jamming in 3 s. On honest GPS there were 0 false alarms out of 939 fixes while moving.

There are two weak spots. A very slow sideways drag, below about 2 m/s on a motorway, isn't caught yet: at that scale the dead-reckoning error is comparable to the drag. And there's spoofing while parked. The car isn't moving, the wheels say zero, and a spoofed GPS also says "stopped", just in another city, so the wheels can't help. The app remembers the last trusted position and rejects fixes further than 500 m + 40 m/s × the time elapsed since then.

Once even that wasn't enough. At night, a phone at home without the adapter accepted a spoofed fix 110 km away: the last trusted position was from the evening, and you could drive that far in a few hours. So on Android there's now a second witness, the network location from Wi-Fi and cell towers. If GPS is more than 5 km from a fresh network fix, it isn't trusted.

Nothing leaves the phone

There are no accounts, no analytics, no ad SDKs and no backend. Routing, guidance, map matching and the GPS check all run on the device. The app goes online for only two things: OpenStreetMap tiles for areas you haven't driven yet, and address search when there's a connection. Only the query text is sent.

This isn't only about privacy. Where GPS is jammed, mobile data is often bad too, and a navigator that needs to ask a server something at that moment is useless.

What actually broke

None of the hard bugs were about the sensors. The sensors are great: pure dead reckoning with the right gyro bias closed a 6 km loop with about 15 m of error, with no map and no GPS. The trouble was my logic around them:

  1. A phone held in a hand. For the first minutes of a drive the phone was in someone's hand, and the navigator dutifully turned along with the hand. Now it detects that the phone is being moved and learns nothing during that time.
  2. iOS suspends the app. The car keeps driving while dead reckoning stands still. PID A6, the odometer, saved me: after waking up the app sees how far the car went without it, and if it was on a road, it advances that distance along the same road. A 5 km gap without GPS shrank to a few tens of metres.
  3. The crawling U-turn and gyro bias, described above.

All of this only showed up in real drives. So every drive is now logged in full and replayed on a computer by the same code, a few seconds per drive, so every change can be run dozens of times.

Limits

  • You need an ELM327 with Wi-Fi or BLE and a car with OBD-II (most cars since about 2001). Without the adapter it's a normal GPS navigator, but with the spoofing check.
  • Below 1–3 km/h OBD reports no speed, so parking manoeuvres are less accurate.
  • The very slow sideways GPS drag isn't caught yet.

Try it

Gorizont is on the iPhone App Store, with CarPlay. It's not in the EU storefront yet. The Android version, with Android Auto, is in closed testing.

https://apps.apple.com/app/id6840547326

I'd love recordings from places where GPS gets jammed or spoofed, and the names of adapters that didn't connect. If you work on navigation or telematics and want to argue about the method, I'm in the comments.