
The China GPS shift problem - ivank
https://en.wikipedia.org/wiki/Restrictions_on_geographic_data_in_China#The_China_GPS_shift_problem
======
Animats
What you really get from GPS is a vector in earth-centered, earth fixed (ECEF)
coordinates. The origin is the rotational center of the earth, the XY plane is
the equator, and the XZ plane goes through the prime meridian at Greenwich.
You run this through a simple standard formula which models the Earth's
slightly elliptical shape, and get out latitude, longitude, and elevation
relative to a defined sea level.

ECEF is based on physical reality. The choice of prime meridian is arbitrary,
but everything else has a physical basis. GPS, GLONASS, and Galileo all
generate (almost) the same ECEF coordinates. (GLONASS has a position for the
center of the earth about 3mm from GPS. Galileo is also about 3mm different.)
This reflects when measurements were made.

Latitude and longitude are computed by putting ECEF coordinates into a geoid
model. All such formulas are approximations. WGS-84 is used by most of the
world. GLONASS uses PZ-90, which is slightly different from WGS-84 and fits
the earth's profile better in Russia. The Chinese "encrypted" geoid is WGS-84
with some junk offsets added for coordinates within China's area of
interest.[1] There's an actual "out of China" test:

    
    
        outofChina <- function(lat, lon){
          if(lon < 72.004 | lon > 137.8347) return(TRUE)
          if(lat < 0.8293 | lat > 55.8271) return(TRUE)
          return(FALSE)
        }
    

This is a rather expansive view of China; this goes almost to the equator,
including all of the South China Sea and the Spratly Islands.

[1]
[https://github.com/caijun/geoChina/blob/master/R/cst.R](https://github.com/caijun/geoChina/blob/master/R/cst.R)

~~~
ChrisFoster
There's some interesting complications to the idea of an underlying Cartesian
ECEF coordinate system as physical reality. For one thing, gravitational
distortion (Earth tide) changes the shape of the solid part of the Earth by
~50cm twice a day. This would be a huge unwanted effect when doing high
precision surveys, but it's removed when producing coordinates in the
international terrestrial reference frame. If you have a nearby reference
station which shares the common periodic motion this is relatively easy. If
not, the software needs to be aware of the periodic motion and remove it
explicitly.

I'm constantly amazed that the whole system can be made to work at such high
precision - sub 10cm from a moving aerial survey platform with decent gear.
There's rather a lot of correction factors to get just right when pinning a
consistent coordinate system on a squishy rotating blob like the Earth.

------
acqq
This part of the article explains more:

[https://en.wikipedia.org/wiki/Restrictions_on_geographic_dat...](https://en.wikipedia.org/wiki/Restrictions_on_geographic_data_in_China#GCJ-02)

"GCJ-02 (aka Mars Coordinates) is a geodetic datum formulated by the Chinese
State Bureau of Surveying and Mapping, and based on WGS-84.[12] It uses an
encryption algorithm[13] which adds apparently random offsets to both the
latitude and longitude, with the alleged goal of improving national
security.[14][15]"

"Despite the secrecy surrounding the GCJ-02 encryption, several open-source
projects exist that provide conversions between GCJ-02 and WGS-84, for
languages including C#,[20] C, Go, Java, JavaScript, PHP,[21] Python,[22]
R,[14] and Ruby.[23][24] They appear to be based on leaked code.[25]"

~~~
ex3ndr
Interesting that there are actually no encryption at all, just simple math
equations.

~~~
chias
> just simple math equations

To be fair, you could say the exact same thing about any modern encryption
scheme.

~~~
GavinMcG
"Simple" is... debatable. There's a good reason rolling your own is a bad
idea.

~~~
teambob
The 'how' of encryption is often quite simple - it is 'why' that is difficult

~~~
reitanqild
Or the other way around?

Example: We all know why we should protect against timing attacks. How to get
it right is the harder part.

------
matthewrudy
At work we've standardised on Baidu coordinates in China.

Even though they're "encrypted", the encryption is locally smooth.

Points may vary by 2km from their wgs84 equivalent, but taking two points 2km
away, using the haversine formula will still yield a distance ~2km.

This means we can treat wgs84 and baidu-coordinates as equivalent, but not
comparable, which makes a lot of things simpler.

Note: we don't do cross border orders, so we don't need to worry about cross
border comparison.

Interestingly, Baidu uses it's own additional encryption on top of GCJ-02, so
we are very much locked in

[https://en.m.wikipedia.org/wiki/Baidu_Maps#Coordinate_system](https://en.m.wikipedia.org/wiki/Baidu_Maps#Coordinate_system)

~~~
nightcracker
Why do people call this encryption when in reality obfuscation is a much
better word for it?

~~~
easytiger
hashing?

~~~
masklinn
It's not a hash since it's reversible.

------
TazeTSchnitzel
China also makes it illegal to make maps of the country without authorisation.
Don't get caught working on OpenStreetMap there.

~~~
maybeok
Every inch of the earth has been mapped out by satellite and is available with
perfect GPS navigation. Too late for that law.

~~~
cjslep
To support you, the USSR had mapped nearly the entire world (presumably with
aid of satellites and GPS):

"The Soviets made far more detailed maps of some parts of the world. They
mapped all of Europe, nearly all of Asia, as well as large parts of North
America and northern Africa at 1:100,000 and 1:50,000 scales, which show even
more features and fine-grained topography."

I sincerely doubt they have any of the China GPS offsets.

[http://www.wired.com/2015/07/secret-cold-war-
maps/](http://www.wired.com/2015/07/secret-cold-war-maps/)

~~~
TazeTSchnitzel
Sounds like their civilian maps did, though:

> Worse, the maps for the masses were deliberately distorted with a special
> projection that introduced random variations. “The main goal was to crush
> the contents of maps so it would be impossible to recreate the real
> geography of a place from the map,” Postnikov tells me. Well-known landmarks
> like rivers and towns were depicted, but the coordinates, directions, and
> distances were all off, making them useless for navigation or military
> planning, should they fall into enemy hands. The cartographer who devised
> this devious scheme was awarded the State Prize by Stalin.

~~~
rdtsc
Yes those Soviet era maps were military and classified.

They only ended up in popular circulation after a quick retreat, fuckup and
corruption that happened when the Soviet forced retreated from the Baltic
states.

I've heard even US militaryused(uses?) some of those maps for parts of Africa
or used then initially in Afghanistan. As nobody else has bothered much to go
and cross reference and built detailed maps of those regions in that much
detail.

~~~
kbart
My history teacher claimed she had seen one of these maps and accuracy was
unbelievable, there were every minor remote woods path marked only known and
used by locals.

------
kylehotchkiss
Just wondering, how does this impact national security? When most of the
planet is well-covered by Satellite imagery, isn't finding an installation
with 500m difference a matter of searching images?

~~~
tw04
It's just an excuse to force foreign companies to license the algorithm.
There's 0 chance foreign nations don't have a copy of the encryption
algorithm.

~~~
lutoma
I mean, there's open source implementations linked in the same Wikipedia
article:
[https://on4wp7.codeplex.com/SourceControl/changeset/view/214...](https://on4wp7.codeplex.com/SourceControl/changeset/view/21455#EvilTransform.cs)

~~~
tw04
Which, as mentioned, are technically created via illegal means. And
incorporating them would into a commercial product would likely see your
product banned from sale in China.

~~~
userbinator
I doubt it's easily enforceable though. This is China, where everything goes
(as long as you know the right people and/or have money.)

~~~
Tomte
Quite a few very influential people thought so, as well. They are being
executed on disciplinary charges (ie. corruption).

------
Theodores
I don't think the 'National Security' aspect would result in Uncle Sam's
finest B52's using Chinese 'GPS' to then end up dropping their bombs 500m off
course in every instance.

That would make a good story though, a full on first strike that missed every
target '500m to the East' due to some mapping oversight.

However, as for real use 'National Security', you could hide some area by
making it not exist with the surrounding area stretched a bit on the map to
hide the secret area. With some natural features, or even a big forest, all
kinds of things could be hidden from the general public (who are important and
primary 'targets' for 'National Security') if not Uncle Sam.

~~~
kbart
" _That would make a good story though, a full on first strike that missed
every target '500m to the East' due to some mapping oversight."_

Something similar has happened at least once(0)..

0\.
[https://en.wikipedia.org/wiki/United_States_bombing_of_the_C...](https://en.wikipedia.org/wiki/United_States_bombing_of_the_Chinese_embassy_in_Belgrade)

~~~
ATsch
Also reminds me of the less map-related targeting deceptions of WWII

[https://en.wikipedia.org/wiki/V-1_flying_bomb#Deception](https://en.wikipedia.org/wiki/V-1_flying_bomb#Deception)

------
reion
I have run into this problem when I was living in China and wanted to map
hiking trip with my friends in HangZhou.

Wrote about it on my old blog in 2013:
[http://michalkow.tumblr.com/post/43214865761/compensate-
for-...](http://michalkow.tumblr.com/post/43214865761/compensate-for-google-
maps-inaccuracy)

------
reustle
I was just in China over the border from Hong Kong and Google maps felt to
just be offset to the west and a bit north by about 500m. Once you mentally
adjusted to that, the maps still felt very accurate. Check out the border and
look how the roads are all cut off at the border, very weird

~~~
janekm
Oddly, when I checked during the last few days Google Maps suddenly got a lot
better, including 3D buildings and accuracy to about 50m for GPS location.
Maybe something changed recently? There have been rumours about Google re-
engaging in China (to fix their Android woes)

~~~
janekm
So it wasn't after all, with more testing... I must have been lucky and hit a
spot where the obfuscation distance was small.

------
ggambetta
I experienced this myself and it was completely confusing!

Back in 2008 before I had a smartphone with GPS, I had a camera and a separate
GPS device I would use to "tag" places where I took interesting pictures
during a 6-month trip around the world.

When I got back home I ran some code to match picture timestamps with GPS
timestamps, correcting for time zone offsets (GPS was GMT, pictures were
local). All of the pictures of the rest of the countries matched just fine,
except for China :) Since I had relatively few data points, it took me a while
to realise there was a systematic error in the data, not something I was doing
wrong with the timestamps.

------
y04nn
Now I understand why when I was in South East Asia there was sometimes a shift
(about 10m), I thought it was a signal reception problem. I was using Symbian
Maps (now Nokia Here). So the correction was not perfect.

------
haosdent
we use baidu map.

