Using google maps without API Keys?

后端 未结 6 2035
时光取名叫无心
时光取名叫无心 2020-12-11 16:01

I am developing a CMS that will use more than one domain and I have to use only one google map script in my page.

Is there a way to use google maps without API key?<

6条回答
  •  有刺的猬
    2020-12-11 16:50

    If you want to vary the API key (for V2) in JavaScript, you can write a wrapper that contains the code for starting your map. The JS code then outputs an API key based upon the host name:

    if (document.domain=="[HOSTNAME 1]") {
    
      document.write('[JS TAG to Google Maps API with HOSTNAME 1 Key]')
    
    } else if (document.domain=="[HOSTNAME 2]") {
    
      document.write('[JS TAG to Google Maps API with HOSTNAME 2 Key]')
    

    etc...

提交回复
热议问题