Using google maps without API Keys?

后端 未结 6 2043
时光取名叫无心
时光取名叫无心 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:43

    According to the Google Maps API FAQ page:

    The Google Maps JavaScript API v3 and the Maps Image APIs previously did not require an API console key. This is still supported for legacy applications to ensure backwards compatibility, but is no longer recommended for new applications.

    I'd also point out that their examples don't include an API key either:

    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    

    Like Chris B said in his answer, you do need to have a Google Maps API Premier key if it is for commercial use. See the FAQ on the subject.

    0 讨论(0)
  • 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...

    0 讨论(0)
  • 2020-12-11 16:51

    This is possible with any version of the Google Maps API, as described here. Basically the only thing the map actually does if used without a key is display an alert complaining about it. If you trap the alert and prevent it from being displayed, the map will function as normal.

    Example here: http://codethink.no-ip.org/mapHacks.html

    0 讨论(0)
  • 2020-12-11 16:56

    The Google Maps API V3 does not require a key.

    Like V2, however, you can only use it for applications which are free and publicly accessible. If it's for a commercial product, you'll need the Google Maps API Premier

    0 讨论(0)
  • 2020-12-11 16:56

    Fairly confident that in order to use their API you need an API Key.

    Perhaps Google maps premiere can adhere to your specific problem?

    0 讨论(0)
  • 2020-12-11 17:06

    Can you add an ApplicationSetting to your Web.Config file like so

    <appSettings>
      <add key="GoogleMapAPI" value="XXXXXX" />
    </appSettings>
    

    for each domain?

    Then add this to your Page

    <script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=<%=ConfigurationManager.ApplicationSettings["GoogleMapAPI"] %>&hl=de"
    

    You could rig up something similar using your database or your host headers to manage each key per domain.

    0 讨论(0)
提交回复
热议问题