ember-g-map icon indicating copy to clipboard operation
ember-g-map copied to clipboard

Support use of ember-g-map from China

Open arturalkaim opened this issue 7 years ago • 3 comments

The url https://maps.googleapis.com/maps/api/js is blocked in China and http://maps.google.cn/maps/api/js should be used instead.

https://developers.google.com/maps/documentation/javascript/localization#GoogleMapsChina

Is there a way to handle this? Or only gracefully handle the error without breaking everything?

Thank you!

arturalkaim avatar Feb 23 '18 14:02 arturalkaim

I think the quickest fix would be to use the exclude: true option in config/environment.js and handle loading the google maps script yourself in your index.html. The best solution i can think of is to serve a different version of your index.html (with the google.cn script src) to users in China.

It'd be great if we could find a way to have the addon handle this, but I'm not sure there's a bullet-proof client-side solution for this problem. I'm open to suggestions though.

steveszc avatar Feb 23 '18 18:02 steveszc

On my index.html I have:

  <script src="//maps.googleapis.com/maps/api/js" type="text/javascript"></script>
  /* Fallback for google maps api for China  */
  <script type="text/javascript">
    if (  typeof window.google == 'undefined' || typeof window.google.maps == 'undefined') {
      document.write(unescape('%3Cscript type="text/javascript" src="//maps.google.cn/maps/api/js" %3E%3C/script%3E'));
    }
  </script>

This way at least it's not breaking. This would also allow you to always load something in the plugin code.

But thanks! Your suggestion will probably fix my issue.

arturalkaim avatar Feb 23 '18 18:02 arturalkaim

I added a note about this in the readme in PR #128 I will leave this issue open for now. I think the solution @arturalkaim shared is reasonable but may not be appropriate as a default behavior for the addon. I'd still like to solve this in the addon though.

steveszc avatar Feb 23 '18 19:02 steveszc