React native geolocation in China

David Yu
Shanghai Coders
Published in
2 min readJan 9, 2018
Photo by henry perks on Unsplash

If you have been to China, you might already know that there’s no Google map here. Then what happens if you want to make an app with a map?

No worries, although different, but not too different. China’s two biggest geolocation providers: Baidu and Gaode(AMap) can be quite handy too.

What to choose? Depends on your requirement

If you are just looking for a map to display a static location, either Baidu/Gaode can do the trick.

If you are looking for location tracking, drawing polylines on map, heat map, indoor map, there’s a nice react native module that supports it.

The process goes like 1. Apply for an access key 2. npm install/yarn install the module into your app 3. Link the necessary library and frameworks

To apply for Baidu map API

http://lbsyun.baidu.com/

To apply for Gaode map API

http://lbs.amap.com/

Baidu Map react native module

https://github.com/lovebing/react-native-baidu-map

Gaode react native module

https://github.com/qiuxiang/react-native-amap3d

Things that I have learned

The coordinates provided by the react-native Geolocation module are DIFFERENT from the coordinates on Baidu or Gaode map.

If you have a large react native project, experiment on a fresh react native build first, because there are a lot of libraries and frameworks to be linked, if something goes wrong, your whole project ends up with too many unnecessary bugs.

Distance interval and timeouts are crucial to prevent GPS from drifting if you are doing location tracking.

If you are drawing polylines with the coordinates that you collected, you could use the Douglas Peucker algorithm to smooth out the lines

If you have any questions, please feel free to share them below in the comment section.

For more information, please visit: https://shanghaicoders.com

--

--

David Yu
Shanghai Coders

Full-stack developer based in Shanghai. I help people turning their ideas into reality.