13

I'm using the latest Google Maps iOS SDK in my app and it seems the GPS location is always offset in China by 1-2 street blocks, however, in the Google Maps official app the location is 100% correct.

I came across this post which seems to be the reason why: http://home.wangjianshuo.com/archives/20081109_all_maps_in_china_are_transformed.htm

It seems the official app uses a correctly transformed map while the Google Maps iOS SDK doesn't. Has anybody found a way around this?

Braiam
  • 1
  • 11
  • 47
  • 78
Josh
  • 211
  • 2
  • 5
  • I downloaded the latest API 1.2.1 and still have the same problem. Using SDKDemos provided the location shown is different from the location on the official google maps. Always out by 1-2 blocks. Seems to be just in China. Any fix? – Josh Apr 26 '13 at 04:28
  • Yoru issue is fixed or not ? are you testing on simulator or Device ? – Syed_Adeel Jun 29 '14 at 07:28
  • 3
    I've created a category on CLLocation that can offset the position in China to compensate for the error: https://github.com/maxime/ChinaMapDeviation – maximeguilbot May 17 '13 at 11:33
  • http://www.sinosplice.com/life/archives/2013/07/16/a-more-complete-ios-solution-to-the-china-gps-offset-problem – Robert Harvey Apr 07 '15 at 02:07

2 Answers2

9

The reason for the GPS offset in China is a combination of technology (different datums) and political/economic interests.

Due to "security concerns", China uses a different coordinates system from the rest of the world - GCJ-02 instead of the WGS-84 standard used by GPS satellites and the vast majority of maps. All maps of China must be approved by the State Council in order to mark China's position on various politically disputed possessions (Tibet, Taiwan etc.). Approval also requires that the maps use GCJ-02. This causes WGS-84 locations, such as GPS tracks from an unadulterated GPS receiver, to appear "off" when plotted on Chinese street maps.

GPS coordinates appear offset on GCJ-02 map

A different coordinate system isn't normally a problem, but China chose to encrypt GCJ-02, so there was no straightforward transformation. The first attempt at a conversion used a database of coordinates obtained from Google China Maps (ditu.google.com) when it used to be able to calculate the deviation back in 2010. This was an interpolation method and somewhat imprecise. Data sets went for sale with offsets calculated for thousands of Chinese cities.

In the meantime the GCJ-02 algorithm has been leaked and is a "public secret" (searching for "GCJ-02 conversion" finds plenty of results). Of popular note is the eviltransform project, which offers conversion APIs for C, C#, Go, Java, JavaScript and PHP. The geoChina library handles conversion among GJC-02, WGS-084 and Baidu's BD-09, using R.

The code is non-trivial, and also performs a very rough bounding box check to determine if a location is in China:

function outOfChina(lat, lng) {
    if ((lng < 72.004) || (lng > 137.8347)) {
        return true;
    }
    if ((lat < 0.8293) || (lat > 55.8271)) {
        return true;
    }
    return false;
}

That includes most of India, all of South and North Korea, Philippines, Vietnam, Mongolia, Thailand, and a host of other countries:

enter image description here

An improvement would be to use a polygon boundary, such as china.kml.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
0

Isn't this due to the different coordinate system used in China to the one we use of WGS84?

Here is some code that can handle translations from WGS84

Lee Armstrong
  • 11,420
  • 15
  • 74
  • 122
  • 2
    Apparently it's [not very clear if that code also takes care of the GPS deviation](https://github.com/googollee/eviltransform/issues/6). – Dan Dascalescu Apr 06 '15 at 09:17