Tag: Apple


16

Jul 2013

A More Complete iOS Solution to the China GPS Offset Problem

This is a guest post by a friend, [unnamed for now]. It goes quite in-depth into China’s GPS issue, which I’ve complained about here before. The hope is that, armed with the following information, non-Chinese developers will be able to get around the issue more quickly and more effectively. Note that while the information below was applied to iOS app development, it isn’t strictly iOS-specific.


Description of the Problem

One problem that often comes up when people stay in China for an extended period of time is that they find their GPS devices don’t work. Sure your iPhone or Android phone will report your own location just fine, but try using a route tracking feature when you’re jogging or if you use an app showing other people’s GPS locations like Find My Friends, you’ll likely see they’re standing in a river or some place 500 meters away even if they’re standing right next to you.

This is the mysterious China GPS offset problem. This has been covered in a few posts [in Chinese] here, here, and here. Basically the Chinese government strictly controls mapping data within China. It’s illegal to map or create GPS traces within China without authorization. There have been stories of a few foreigners who created hiking trails near sensitive buildings w/ GPS devices being arrested due to relevant local laws.

For popular map apps such as Google Maps or Apple Maps on iOS, the user’s own location will be correct. This is because licensed companies that register with the government will be given the corrected algorithm to adjust the user’s position. Google Maps, Bing and others allow you to search for a location based on the GPS coordinates, but no local Chinese map providers such as Baidu Maps allow you to.

If you had taken a photo near the Forbidden City, load the photo into iPhoto or Picasa and look at where it is on the map you’ll see the location is just a bit off, 300-500 meters and typically about a block or two away. Not far enough to be extremely inaccurate but incorrect enough to annoy and not place you in the proper position.

Baidu Maps offset example

Fig 1. Example of proper position at Xujiahui and the offset location to the northwest

Two GPS standards

The most common GPS standard used internationally is based on a coordinate system called WGS-84. The globe is an imperfect sphere and any mapping from 3D to 2D introduces some compromises. People who get really into it will note that as you get further away from the equator, the way GPS coordinates for latitude and longitude change aren’t the same even if you’re traveling the same distance. However this is the GPS we’ve come to know and is used globally.

China uses a standard called GCJ-02 which is based off an older Soviet system of coordinates introduced in the 1940’s. It’s converting from WGS-84 to GCJ-02 that we’d like to accomplish. Chinese programmers refer to this coordinate system as the 火星坐标系统 or “Mars coordinate system” (as in you’re mapping from Earth with WGS-84 to Mars in GCJ-02).

Preliminary tries to correct the problem

Static offset

The first tries in the English-language world to correct for this China offset problem noticed that in local areas like within the city of Shanghai or Beijing, the difference was relatively fixed. That is, if you just subtract a few degrees from the latitude and add a few for longitude, you can correct the position. They quickly realized that the translation was non-linear, though, changing from city to city.

Collecting data points

Approaching this problem myself, I found out that as long as I was within China’s IP range, I would see the iOS simulator report my simulated location correctly, but if I dropped a pin on the same GPS coordinates it would be off. I created a simple app that let you drag the pin back to your real location and after scraping Wikipedia’s list of cities in China, had 657 data points.

Data_points

Fig 2. 657 points taken from list of official cities in China from Wikipedia

Using Excel’s LINEST function you can split the data up into groups and actually get a pretty decent correction that works across the whole country although it will still be off by a few meters. Enough to put you across the street from where you really were or down a few stores.

google data

Fig 3. Example of Google data point set with offsets

It turns out if you search in Chinese, several people sell massive data sets of tens of thousands of points within China with their corresponding offset. Apparently people have run into this need before. On Taobao you can find sets from 400 RMB to 900 RMB.

datasets for sale 3

Fig 4. Example of data set for sale on Taobao

Hints at already solved code

A few English language posts stated that Chinese Android coders had already released the proper algorithm in open source. After several searches in Chinese, finding relevant posts was easy. But the actual ones that solve the problem took more hunting until I found the personal website of Rover Tang and a post on a popular tech site called XCoder.cn.

Solution found and explained

Keeping it brief, the originally released code was a C file that took into account all sorts of height, GPS time and date etc. even though they were unused. This could be found several places online. A refactored and cleaner version of the code is available in C# on EvilTransform.cs.

It’s basically a complicated transform using equations describing an ellipsoid (what the Earth is) from one system of coordinates to another. Once you throw in GPS in WGS-84 you get the same ones back in GCJ-02.

You’ll note that the code interprets that anything within China needs this conversion, anything outside of China, doesn’t. And that China is defined as anything between Latitude 0.83 to 56 and Longitude 72 to 138. I think there’s a few countries caught in that rectangle that might object.

So what now?

So now any web or mobile app developers who need to record GPS paths, post GPS locations, or anything else on top of a map can now have the proper locations. It was a huge relief to me to finally find a solution that works anywhere in China so we can all go back to creating apps that work.


References


Dec. 23, 2014 Update:

A developer recently found this post vey useful in solving his own China location app problems, but needed some additional information to properly implement the above advice. I’m sharing that extra information below in the hope that it’s useful to more developers:

  1. Apple returns their coordinates in the WGS format and offsets the map when rendering (I thought the coordinates themselves were offset, not the rendered map).

    Not mentioned but deduced from the above was that Google does it the other way around… if I’m not mistaken, Google returns the GCJ coordinates for a China location (even if you are not in China)… This explains why Apple’s coordinates are off when input into Google until they are converted into GCJ.

  2. MapKit only offsets the map from devices within China.

    Because we were testing on devices in and out of China we weren’t sure where the root problem was; we had tried the conversion, but then tested the results with MapKit on a device that was outside of China.


25

Sep 2012

iOS6 has your iPhone speaking Chinese

I got a great tip from my friend Will Stevenson yesterday. Apparently iOS6 not only added text-to-speech support for new languages, but also enabled the ability to recognize and read out Chinese, even when the phone is in English language mode, and even when the text is a mix of Chinese and English.

What it is

Here’s an example of “Speak” enabled for a Chinese spam text:

IMG_0660

Here’s an example of “Speak” for a note which includes both English and Chinese (I’m not sure why there’s a choice of reading in either 中文 or English; either one does the same thing):

IMG_0658

Untitled

For text messages, iOS treats each SMS text as one big block of text, and it won’t highlight individual words as it reads them (even though it reads them all). For other types of text, though, in apps like the Notes app, it will highlight each character as it reads it out:

IMG_0659

grassroots

[Side note: here’s what the note was about. I took notice of it because it’s a fairly rare example of mixing simplified and traditional Chinese characters in print. It was done to put the (heart) back into the character for love, since the simplified version quite literally takes the “heart” () out of (traditional) “love” ().]

How to enable it

Anyway, since you’re likely here to get your iOS6 device speaking Chinese, here’s how you do it.

First, go to Settings > General > Accessibility (Accessibility is near the bottom of all the stuff in “General.” Just a little hard to find. Naturally.)

Right at the top, you’ll see an Accessibility section called “Vision.” There you’ll see an item called “Speak Selection.” Touch on that. On the next screen, turn it ON. You can also turn no “Highlight Words” here too (why not?). You probably don’t want to mess with the speaking rate. It gets way too fast pretty quickly.

IMG_0653

IMG_0654

Here’s the really cool thing, though. There’s a “Dialects” section. (And no, I’m not going into the “what is a dialect, really? discussion here!) In there, you can not only choose the dialect for English and other languages, but also for Chinese! At the bottom of the “Dialects” section, under 中文, you can choose mainland Mandarin (中国), Cantonese (廣東話), and Taiwanese Mandarin (台灣). Not sure why they chose two regions and a language/dialect/topolect as the choices. But anyway, fun stuff!

IMG_0656

IMG_0657

What it means

Why does this matter? Well, my friend Will discovered it by accident as he was going through the somewhat tedious routine of copying a text so that he could then paste it into Pleco‘s pasteboard reader. He tried playing the text, and much to his surprise, he could hear the Chinese (whereas in the past, on iOS5, the text-to-speech converter would just skip over all Chinese). In this particular example, after having the Chinese read to him, he didn’t need to look it up after all.

Because a lot of the challenge of Chinese is simply recognizing the characters for the words you already know, text-to-speech can be extremely convenient. Will’s reaction was, “now that I have this feature, I’m going to be using Pleco a lot less now!”

Interesting. Let me know if you think this new feature changes how you learn Chinese on your phone, or if it’s just no big deal to you.


A New iPad App for Learning Pinyin

19

Apr 2012

A New iPad App for Learning Pinyin

I’m very happy to finally announce that AllSet Learning has just released its first iOS app for the iPad, called AllSet Learning Pinyin. It’s a simple app, designed to take the typical pinyin chart we all start learning Chinese with and adapt it to the iPad. So that means supporting multiple orientations, as well as zooming and panning. And, of course, tapping for audio.

Last year AllSet Learning’s clients started buying up iPads at surprising rates, and all the beginners had the same request: I want a pinyin chart designed for my iPad. So that’s what we built.


More screenshots available on the product page

The app is free, and comes with not only audio for all pinyin syllables in all four tones, but also support for non-pinyin phonetic representations. So you can switch from pinyin to IPA, and even to other systems like Wade-Giles and zhuyin if you purchase the (very inexpensive) addons.

More addons for the app are coming. In the meantime, please try it out, tell your friends about it, and rate it in the App Store. Thanks!


Related Links:

AllSet Learning Pinyin on the App Store
AllSet Learning Pinyin on the AllSet Learning website


28

Feb 2012

Unmixing Chinese and Japanese fonts on the iPad and Mac OS

Recently an AllSet Learning client came to me with an interesting problem: he was seeing strange, slightly “off” variations of characters in his ChinesePod lesson, “Adjusting the Temperature.” Once upon a time I studied Japanese, so I could recognize the characters he was seeing as Japanese variants:

What he saw:
ChinesePod fonts (with Japanese characteristics)

What he expected to see:
ChinesePod fonts (fully simplified Chinese)

[If you really care about the tiny discrepancy, you may need to click through and enlarge the screenshot to see the difference. I’m not going to focus on including text here, because that’s exactly the nature of the problem: the text is subject to change based on your system’s font availability.]

The really strange thing was that he was experiencing the exact same issue on both his 2010 MacBook and on his iPad 2. In troubleshooting this problem, I discovered that my client was running both an older version of iOS (4.x) as well as an older version of Mac OS (Leopard). I was experiencing neither on my 2008 MacBook (running Snow Leopard) or on my iPad 2 (iOS 5.x). But his system had all the required fonts, and switching browsers from Safari to others did nothing to solve the problem. So I concluded it was simply a system configuration problem.

Fixing the issue on the iPad

Here’s the fix. On the iPad, go into Settings > General > International (you might need to scroll down for that last one). You might see something like this:

iPad Language Settings (2)

Note that in the order pictured above, Japanese (日本語) is above simplified Chinese (简体中文) in the list. This is crucial! That means that if English fonts are not found for the characters on a given page, the system is going to match characters to Japanese fonts next.

So to fix this issue, Chinese should be above Japanese. The thing is, there’s no obvious way to change the order. The only way I found to do it is to switch the system language to Chinese, then switch back to English. [Warning: your entire iOS system interface will switch to Chinese when you do this; make sure you can read the Chinese, or you know where the menu position for this settings page is before you switch!]

(Hint, hint!)
iPad-language-settings-Chinese

Switching to Chinese makes the Chinese jump to the top of the list, then switching back to English makes English jump back above that, leaving Japanese below Chinese.

You should see something like this when you’re done:

iPad Language Settings (1)

Fixing the issue on Mac OS X

The exact some issue applies to Mac OS X system preferences. Go to: System Preferences… > Language & Text > Language.

Mac OS System Preferences

This time, though, there’s an easier way to rearrange the order. Simply click and drag:

Mac OS Language Settings

Notice the little message on the right about when the changes will take effect.

Does this really matter?

In the grand scheme of things, not really. It’s actually good to have some tolerance for font variations. But the detail-oriented may find this particular issue quite maddening. It’s good to have a simple way to fix it.

So why didn’t I have the issue, and he did? Well, I had at some point tried switching the system language to Chinese, on both my MacBook and on my iPad, but I later switched them back to English. So without even trying to, I had taught my system to prefer Chinese over Japanese. The problem appears when English is the only language ever used, and the system doesn’t know what to give preference to. In my client’s case, you would think that adding a Chinese input method might clue in the system, but apparently Apple isn’t quite that on the ball yet.


20

Dec 2011

Xiami’s Unofficial iPhone App

Recently a Chinese friend got me into Xiami. In case you’ve never heard of it, TechRice describes it like this:

> Xiami is perhaps the closest China has to a Last.fm, though in Last.fm users have to pay monthly subscriptions to listen to songs and Xiami is still completely free up until the point of download.

So think “social music site,” with both free and paid offerings.

I was interested to see how the site offers its iPhone app for download:

Xiami's iPhone app

So what that little popover message is telling you is that you have to download the iOS install file (.IPA file), and it only works on (illegally) jailbroken iPhones.

I’ll admit I don’t have a lot of experience with Chinese iPhone apps; I mainly just use a handful of them. I’m curious how many other relatively large and popular services are doing it this way now. Xiami as a service seems much “more legal” from a western perspective than services like Baidu’s MP3 downloads, but then they go and do this with their app (presumably because Apple won’t approve the app).

Anyone?


More about Xiami:
China’s Internet Music Industry, You Pay For Music Now (TechRice)
Xiami versus Grooveshark (TimeOut Beijing)


19

Aug 2011

Word Tracer Apps for Sinosplice Readers

iPad Apps for Writing

A while back when I wrote my Learning to Write Chinese Characters on the iPad post, I reviewed an iPad app called Word Tracer. Word Tracer is going strong, and now comes in both iPad and iPhone flavors. In addition, the developer has added some additional functionality to the app in a recent update, allowing for Chinese writing practice that isn’t strictly “tracing.”

Anyway, to thank me for the review, the developer has offered me a number of free copies of the app (iPad or iPhone) to distribute to Sinosplice readers. If you’re interested in getting a free copy of this app, simply leave a comment here (with your real email) or send me an email explaining why you think that the iPad (or iPhone) makes the most sense to you as a way to practice writing Chinese. I’ll award the best ones in the first 48 hours with a free copy of Word Tracer. (Be serious in your replies; I’m very interested in learning something from this!)


Update: Thanks to all of you who commented and emailed me! The response was really pretty good, and I regret that there are too many of you for everyone to get a free copy of the app. I do appreciate the responses, though, and those selected will receive an email shortly. I’m closing comments on this blog post now.


Chinagram for iPad

19

Apr 2011

Chinagram for iPad

I recently had the opportunity to try out Chinagram, a new iPad app which introduces Chinese characters. There aren’t many Chinese-learning apps out there specifically for the iPad, so I decided to review this one.

My first impression of the app is that it is beautifully made. I guess that’s Italian design for you. The overall aesthetic is nice, and there are lots of little touches that make the app fun to use. Don’t miss the “History of Chinese Writing” section. While the information it contains is not something you can’t find on Wikipedia and many other sites, it’s definitely presented here in a way that’s enjoyable to browse. I especially liked the foreground/background faux-3D effect you get when you swipe to a new page.

After my playing with the app a little bit, the key question in my mind was, who is this app for? Is it for an advanced student? An intermediate student? A beginner? Or maybe just a casual student of Chinese? My conclusion, unsurprisingly, is that it’s for the casual student of Chinese. Sure, a beginner can get some use out of it, but since the app only covers 120+ characters, the serious student won’t be using this one for long. The strength of the app, perhaps, is its treatment of the evolution of the characters it contains. The graphics it contains go further than Wenlin, but certainly not ChineseEtymology.org (which is free). And Wenlin costs a lot more, while ChineseEtymology.org actually has an iPhone app now.

There aren’t yet many Chinese learning apps created for the iPad. Chinagram has got to be the most attractive one currently in the app store, and while it’s still $1.99 it’s a good deal for the beginner or casual learner.