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?
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.
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:
An improvement would be to use a polygon boundary, such as china.kml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With