xoops forums

Peekay

XOOPS is my life!
Posted on: 2016/9/12 10:51
Peekay
Peekay (Show more)
XOOPS is my life!
Posts: 2335
Since: 2004/11/20
#1

Google Maps API Keys are back

Google Maps API Keys are back

To embed Google Maps in a website, webmasters had to register for a free 'API Key' on the Google developers website. Then, Google changed the rules and for a while you could embed maps without a key. Now, from June 2016, API keys are back.

To get keys for your domains that use a Google maps module (you need one for each domain AFAIK) go to:

https://console.developers.google.com

Log in with your Google account credentials. In the API Manager screen - to the right of the Google API logo - you will see a drop-down menu of API projects. If you had registered a key sometime in the distant past, you may find that you already have a project called 'API Project' which is the name given to legacy keys.

Getting a new key

Getting a new key is a two step process. First, you need to create a new project/key combination. To do this, select the aforementioned drop-down menu, choose 'Create Project' then follow the prompts. At some point a window will appear with the key which you can copy. You will need to paste it into a module preference field, or hard-code it into the URL that calls Google Maps.

Step two is to register your site domain with Google. To do this:

* Ensure the correct project is selected in the drop-down menu.
* Select the 'Credentials' option in the left sidebar.
* Click once on the key (the default name is 'Browser key').
* Under the section 'Accept requests from these HTTP referers' do the following:

1) In the empty field, enter the word

Quote:
'localhost'

and press 'Save' (this enables localhost map development)

2) In the new empty field that then appears, enter the actual site URL including the wildcards, e.g.

Quote:
*.mywebsite.co.uk/*

It can take a few minutes for the changes to take effect.

Code changes

There have also been some changes to the way Google maps is accessed. Most importantly, you will need to change the primary script source URL from:

Quote:
to:
Quote:
//maps.googleapis.com/maps/api/js?key=.....

Some of the syntax has also changed, e.g.

Quote:
GMap2 changes to google.maps.Map

Quote:
GLatLng changes to google.maps.LatLng

There are more replacement pairs listed on the Google developers website, but these seem to be the significant ones. You may also need to remove some references to deprecated classes to prevent Javascript console errors. Running Firebug in Firefox will display errors from Google if their map API is unhappy about something.

For example, the addControl() method is deprecated, so in the module that I use I had to comment out:

Quote:
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());

The default map controls are now enabled by default, so map navigation wasn't affected.

There's a good guide to implementing the update at:

https://developers.google.com/maps/articles/v2tov3

HTH */

Peekay

XOOPS is my life!
Posted on: 2016/9/12 13:44
Peekay
Peekay (Show more)
XOOPS is my life!
Posts: 2335
Since: 2004/11/20
#2

Re: Google Maps API Keys are back

**EDIT

Sorry, missed out a step in the above.

You will during the process of getting a new key be asked to choose an API. The one you want is 'Google Maps JavaScript API'.

You can access all the APIs from the 'Library' menu option in the left sidebar.

Peekay

Mamba

Moderator
Posted on: 2016/9/13 11:18
Mamba
Mamba (Show more)
Moderator
Posts: 10347
Since: 2004/4/23
#3

Re: Google Maps API Keys are back

Thank you for the update on this! That's very useful!
Please support XOOPS & DONATE
Use 2.5.8 | Debug | Requests | Bugs

ilsanto

Just popping in
Posted on: 1/9 9:16
ilsanto
ilsanto (Show more)
Just popping in
Posts: 6
Since: 2002/3/2 1
#4

Re: Google Maps API Keys are back

Xoops 2.5.8.1
googlemaps 0.91 beta1
Theme based on xbootstrap

This not working.

In the admin interface the lat e lng are "undefinited".

How to solve this?

Stefano