I can't find a place to enter a google API key. In 8.x-1.x it was in admin/config/geocoder.

Members fund testing for the Drupal project. Drupal Association Learn more


geekygnr created an issue. See original summary.

geekygnr’s picture

Issue summary: View changes
geekygnr’s picture

Category: Support request » Feature request
Status: Active » Needs review
3.25 KB

I copied over the configuration page from 8.x-1.x and implemented the configuration on the Google API provider.

Pol’s picture

Status: Needs review » Needs work


Could you provide the patch for geocoder-8.x-2.x please ?

Thanks !

johannez’s picture

4.14 KB

Hello guys,

thank you @geekygnr for the great work. I took your approach and applied it the current 8.x-2.x dev branch. Instead of the init() function I had to go with the getArguments() function to add the api key.

The form is pretty much the same as yours and should be able to expand for other api keys. I let @Pol expand on that.

It works fine for me, let me know, if you see any troubles with it.

Pol’s picture

Hi Johannez,

I reviewed the patch and it's not how I see the thing at first sight.
I would like to move the form into the plugin itself, that's where it belongs actually.

So here's what's left to do:

  1. Move the configuration form into the plugin itself,
  2. Remove any @todo,
  3. Update the variable name 'api_key' and use an array instead of a string, example:
              api_key: '[KEY]'
              api_key: '[KEY']
              api_key:  '[KEY]'
              other_configuration_item: [VALUE]
aaronbauman’s picture

I'd suggest that config forms should also include a means to enable / disable providers globally.

Seems like there are a couple use cases for this:
1. Reduce the number of providers available to each geocoder_field.
For example, if my app violates Google Maps TOS, I want to make sure admins cannot create a google maps geocoder field.
2. Make it clear which services are appropriate for other modules that use the geocoder service.
For example, I have no programmatic way to distinguish between "Google Maps" provider and "Random".

I see that an instance of a geocoder_field uses its config form to enable particular provider(s).
But all providers are always available to choose from.

Lemme know if you think this is appropriate for this issue, or merits a new one.

Carlos Miranda Levy’s picture

So, other than this patch that maintainer does not like, how does one enter the API key for the module to work with?

dbjpanda’s picture

Status: Needs work » Needs review
4.8 KB

Modified as per comment #6. Kindly review and guide me.

Pol’s picture

Assigned: Unassigned » Pol

I will review this ASAP.


dbjpanda’s picture

@Pol thanks but I am getting this error applying the patch from #9 "An error occurred when fetching the URI "https://maps.googleapis.com/maps/api/geocode/json?address=Bhubaneswar&ke..." with the adapter "curl" ("error setting certificate verify locations: CAfile: C:\Program Files (x86)\DevDesktop\common\cert\cacert.pem CApath: none")." I need the Geocoder module to be worked with one of my project ASAP. So any feedback is appreciable.

afi13’s picture

Hello, guys, any updates for this issue? How can i help you? Looked at the patch from #9, we really need API key settings for each Provider? For example Yandex and Open Street Maps don't require API key.

dbjpanda’s picture

@Pol Did you review it. Any update on this module??

weseze’s picture

Related issue: https://www.drupal.org/node/2834236

You can solve this by extending a geocoder plugin and coding your api key in it.

Example for GoogleMaps:
Create a new module "my_module".
Create the directory structure: my_module/src/Plugin/Geocoder/Provider
Create a new file in that directory MyGoogleMaps.php with this content in it:


namespace Drupal\my_module\Plugin\Geocoder\Provider;

use Drupal\geocoder\Plugin\Geocoder\Provider\GoogleMaps;

 * Provides a GoogleMaps geocoder provider plugin with your API key.
 * @GeocoderProvider(
 *   id = "mygooglemaps",
 *   name = "My GoogleMaps",
 *   handler = "\Geocoder\Provider\GoogleMaps",
 *   arguments = {
 *     "locale",
 *     "region",
 *     "useSsl" = TRUE,
 *     "apiKey" = "YOUR_API_KEY_GOES_HERE"
 *   }
 * )
class MyGoogleMaps extends GoogleMaps {}

Rebuild the cache and you will now have a "My GoogleMaps" geocoder plugin available that will use your key.

The same principle applies for other geocoder plugins.

dbjpanda’s picture

@weseze Thanks.

dbjpanda’s picture

@weseze we need a GUI based configuration form.

dbjpanda’s picture

4.77 KB

This patch fixed the error for me. Kindly someone review if it works for you not?

dbjpanda’s picture

Category: Feature request » Bug report
Priority: Normal » Major
Nick_vh’s picture

  1. +++ b/src/Plugin/Geocoder/Provider/GoogleMaps.php
    @@ -19,4 +19,22 @@ use Drupal\geocoder\ProviderUsingHandlerWithAdapterBase;
    +            // For proper API calls, we have to go through SSL.

    What does this comment mean?

  2. +++ b/src/Plugin/Geocoder/Provider/GoogleMaps.php
    @@ -19,4 +19,22 @@ use Drupal\geocoder\ProviderUsingHandlerWithAdapterBase;
    +            $arguments[3] = true;

    Are we sure this is always parameter 3 and 4?

Did you also run code standards check?

StryKaizer’s picture

Status: Needs review » Needs work

The given patch hardcodes the google api key.
It should dynamicly detect which provider requires an api key, and generate an UI for it.

Also, about @Nick_vh 's comments:

1. The comment can be changed to:
// When doing an API call with an API key, using SSL is required by google.

It looks like these arguments are the one required by ivory curl. This might be out of scope for this feature to fix, but it looks like that order is always param 3 and 4. (It wouldve been nice if geocoder had a wrapper interface for the http_adapter, so people could swap out curl, but as said, out of scope for this feature ;) )

cgmonroe’s picture

Seems like the best way to do this would be to have a Provider Config entity rather than try to fit it into the module's schema.

This could be combined with extracting the arguments from the provider plugin definitions to provide the arguments needed and the default values.

This could also be used as the way to limit the list of available providers to only configured one. If a config entity does not exist for a provider, don't show it. NOTE: With V4.0 of the GeoCoder PhP library, the providers have been split out to individual packages. So limiting the list to installed providers will be important. Selecting one that is not installed will generate a WSOD when geocoder is called.

It would also allow individual provider configs to be transferred between sites and/or added to features as needed.

Pol’s picture


@itamair did a configuration page, it's currently in the dev version, did you tested it ?


tonci’s picture

Category: Bug report » Task
Priority: Major » Normal
4.98 KB

I have added some more api key fields to the form.

cgmonroe’s picture

You should look at the latest Dev code. The config form there is being built based on the Provider plugin arguments. There is no need to mirror this in the config. This is the best way to do this as it allows providers change arguments (like going from V3 to V4 of the Geocoder PhP lib) and/or the use custom provider code. The config form will automatically adjust to these changes.

Also see #2936857: Update to latest-dev fails because of missing config schema update process for issues around upgrading to the latest Dev.