Geolocation - Google Maps

What is Geolocation?

Geolocation is a Drupal module that allows users to include Google maps into custom content types once the installation and configuration steps are completed. It takes the map coordinates (latitude, longitude) and, via an API key, translates that information into a map generated dynamically into your pages.

Request the Geolocation Module for your site

The installation of the module requires the assistance of the SiteFarm team. Please submit a Service Request form and indicate your need for the Geolocation web service. When processing this step for you, the SiteFarm team will also enable the appropriate permissions for configuring your Geolocation settings.

Acquire a Google Map API Key

Visit the Google Maps Platform site's API key page and follow the instructions for obtaining an API key for your site.

Configure your Geolocations settings
  1. Once the module is enabled and the permissions set, navigate to Manage » Configuration » Web services section » Geolocation settings.
  2. Enter your API key in the field:
    A screenshot of the api key entry field in the Geolocation configuration area.
  3. Click the Save configuration button to finish.
Adding Geolocation to a custom content type

The default content types that come with SiteFarm (Article, Basic page, Event, Person, etc) are locked down and cannot be edited. This means you will need to create your own custom content type so you can include the Geolocation entity fields for your users to fill in.

  1. Once you've started your custom content type, click the + Add field button.
  2. Use the 'Add a new field' menu, scroll down and locate the General section, and select Geolocation.
    The Geolocation field type is located in the General section of the field type menu.
  3. Provide a label name for the field. This will be visible to your users filling out the content type.
  4. Click save and continue.
  5. The next screen will ask you to indicate if the number of maps on the page should be unlimited or limited. If limited, but sure to indicate 1 or your specific number. These settings apply to the Geolocation field everywhere it is used. These settings impact the way the data is stored in the database and cannot be changed once data has been created, so be sure of your choice at the outset.
  6. Click Save field settings.
  7. The last screen will give you the option to update/provide:
    • Label name
    • Help text
    • Indicate if it's a required field
    • Enter a default value or leave the Latitude and Longitude fields blank
  8. Click Save settings.
  9. In the content type's overview, click on the Manage form display tab.
  10. Locate your Geolocations field in the list and, under the Widget column, change the menu item from Geolocation Lat/Lng to Geolocation Google Maps API - Geocoding and Map.
  11. In the content type's overview, click on the Manage display tab.
  12. Again, locate your Geolocations field in the list and, under the Widget column, change the menu item from Geolocation Lat/Lng to Geolocation Google Maps API - Map.
  13. In both steps 10 and 12, you have the option to click on the element's cog to access its configuration settings if further customization is desired in terms of title positioning, size, replacement tokens, and map settings.
  14. Click Save to finish.

Troubleshooting

Did you receive the error message "this page didn’t load google maps correctly"? Take a look at the article How to fix “this page didn’t load google maps correctly” error written by Steven Gliebe in March 2019 with suggestions for investigating possible API-related issues.