Using google maps without API Keys?

2019-01-20 08:39发布

问题:

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?

Otherwise, it's not working?

回答1:

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



回答2:

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.



回答3:

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



回答4:

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

Perhaps Google maps premiere can adhere to your specific problem?



回答5:

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.



回答6:

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...