RSSAmplifier

丁宇 | DING Yu · Jul 9, 2020

Use Google Maps Javascript API in China

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

The Problems Google Maps Javascript API from google.com doesn’t work in China as most of Google is blocked (https://maps.googleapis.com/maps/api/js) Google China stopped supporting the Chinese Google Maps API since Feb 2020 (https://maps.googleapis.cn/maps/api/js) The available solutions you can find online (e.g. from Stackoverflow) became obsolete as of today (July 19, 2020) The Solution Be…

The Problems

  • Google Maps Javascript API from google.com doesn’t work in China as most of Google is blocked (https://maps.googleapis.com/maps/api/js)
  • Google China stopped supporting the Chinese Google Maps API since Feb 2020 (https://maps.googleapis.cn/maps/api/js)
  • The available solutions you can find online (e.g. from Stackoverflow) became obsolete as of today (July 19, 2020)

The Solution

Be warned: this is a hack and may stop working at anytime. Use at your own risk.

The solution has been working fine for me for the past month or so (demo):

Google Maps

In general,

  1. Download https://google.cn/maps/api/js?key=YOUR_API_KEY as a Javascript file.
  2. Open it and replace maps.google.cn with google.cn.
  3. Host the modified Javascript on your website and use the API normally.
  4. THIS IS VERY IMPORTANT: after some time the Javascript will expire and stop working, so you have to start from step 1 again. I ended up automating the process in my Rails app.
  5. OPTIONAL BUT ALSO IMPORTANT: you may want to figure out a way to restrict the access to the modified Javascript. Otherwise someone may abuse it and it’s you who needs to pay the bill.

:wq

Read on /blog/google-maps-api-china

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.