The geolocation module supports using two different Google Maps API keys, one for front-end functionality, and one for back-end.

This allows users to whitelist API keys based on HTTP referrer (for the front-end), and by IP address (for the back-end).

However, there's a bug that prevents server API requests from being whitelisted by IP address. It happens in GoogleGeocodingAPI.php in the geocode() method. The method properly checks if there is a server key, but it does not use the server key.

    if (!empty($this->geolocationSettings->get('google_map_api_server_key'))) {
      $request_url .= '&key=' . $this->geolocationSettings->get('google_map_api_key'); // This is incorrect.
    }
    elseif (!empty($this->geolocationSettings->get('google_map_api_key'))) {
      $request_url .= '&key=' . $this->geolocationSettings->get('google_map_api_key');
    }

Will attach patch shortly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

donutdan4114 created an issue. See original summary.

donutdan4114’s picture

Patch fixes the issue and include additional error reporting for when requests fail so you can easily see which IP address or referrer you need to whitelist.

donutdan4114’s picture

Status: Active » Needs review

ChristianAdamski’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jkeasley’s picture

As a result of the changes to Google maps that went into action on 16 july a google maps api key is required in all cases.

This fix needs to be rolled into the production branch, as the backend interface is currently broken leaving user's unable to edit map information

imclean’s picture

We're using both backend and frontend keys, which doesn't work out of the box. See related issue: #2981953: Confusion over server and client API keys