Google Maps - Getting Started

From TNG_Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Ambox notice.png As of June 2016, you must get a map key from Google in order to use Google Maps on your site. TNG V11 download page contains a Maps Patch for those whose Google Maps do not work because no key was provided. Some background to this change is on the Google Geo Developers Blog.

As of 16 July 2018, you must enable billing to use the Google Maps Platform

TNG 12.0
TNG 11.0


Get a Google Maps Key

As of July 2018

You must have a User ID on Google in order to get a browser API key for the Google Maps Platform. If you are already signed up for Google Mail, you can use that User ID, otherwise you will need to create a User ID.

Get Maps API Step Screen Capture
1. To get a Google Maps API key use the following link Additional instructions can be found in the setup guide
2. Create or select your project
Project selection
3. From the API library (section Maps) select and enable the following three keys: Maps JavaScript API , Geocoding API and Places API
  • Maps JavaScript API is needed to show the google map to your site visitors, with a marker at the various places (place of birth, death, mariage etc.)
  • Geocoding API is used in the admin section of your website to associate places with coordinates
API Library
4. Once your API keys are enabled, go to credentials to set the right application and API restrictions
  • For application restriction you can use HTTP referrers (web sites), using the format https://yoursite.com/tng/*
  • For API restrictions, allow the different API keys you enabled to make the requests

Note: Instead of using the HTTP referrer, it might work better to use the IP addresses of your server (use both the IPv4 and IPv6 addresses when existing). This helped me to improve the success rate of doing batch geocoding lookups. Still looking into this for a better fix.

API application restriction

API restriction

Choose Apis
5. Copy your API key.

You will need to paste this into your TNG configuration later, see instructions below "TNG Map Settings"

API-key-credential.png
6. you will also need to enable billing. Depending on the amount of visitors to your site / API requests being made you might get invoiced by Google for the API usage. Most users have learned that their usage stays well below the minimum thresholds, meaning the invoice you receive monthly will be for $0.

Previous Instructions

You can click on the [Expand] link to display the Previous Instructions or the [Collapse] link on the right to hide this section again.
Get Maps API Step Screen Capture
1. When you click the Get Started button, you will be presented a screen to Enable Google Maps Platform.
You will need to select Maps and Places as the options
  • Maps to get the Google Maps Javascript API access
  • Places to get the Geocoding API
  • Route to provide Directions API
Maps Option
Places Option
Route Option
2. You will then need to select a project or create a new project
Select Project
3. You will also need to enable billing


Enable Billing


You must have a User ID on Google in order to get a browser API key. If you are already signed up for Google Mail, you can use that User ID, otherwise you will need to create a User ID.

The Google Maps JavaScript API Guides page on the Google Developers site provides an overview of Google Maps Javascript API use including a "Hello, World" HTML code example.

To use Google Maps with TNG, get a browser API key for your web site by going to the Get API Key page on the Google Developers site.

Note that keys previously obtained for TNG v6 through v8.1.3 for the V2 API will not work with the v3 API.
Get Google Map key


Create a Project

Create a Project

It is recommended that you name your project so you can find your Google Maps API keys later.

It is recommend that you not use the www in your URL when requesting your browser key, so that the key will also work with subdomains, such as tng11beta.useract.com You should also use /* after your domain name so that the maps will work for all sub folders on your site.

NOTE: You must request your key for a Browser API key

Google map api v3 browser key create.png

Note - you need to click the Create button twice - once to enter the details of your domain, and a second time to submit it when the line to enter a second domain is empty.

Google map api v3 key generated.png


See Using Google Maps with TNG on Steve Davis' site for an expanded explanation.

TNG Map Settings

Settings for Google maps in TNG are in your mapconfig.php configuration file, which is created & updated by going to Admin >> Setup >> Configuration >> Map Settings

Setup your TNG Map Settings

You should save the Google Map API key you obtained for your web site in the Map Key field of Map Settings.

Save your Google Map API

You can set the Map Type display to

  • Map
  • Satellite
  • Hybrid (Satellite with location names)

Set option for Hide Admin Maps to Start:

  • No - means the Admin Place Edit will show the map
  • Yes - means the Admin Place Edit will show the Show / Hide Clickable Map button

Set option for Consolidate Duplicate Pins:

  • No - means each event will get a separate pin number
  • Yes - means that events at the same place location will be combined to a single number

Localhost key

If you run a local web server on your desktop, such as MAMP, WampServer, XAMPP, or IIS and you want to test Google Maps on your local TNG installation, you can adjust the API to work on both your website and locally using the same key.

The following process assumes that you have already set up the API and have a key that you are using on your TNG website.


1. Log in to the Google Cloud Platform and from the left-hand menu, click APIs and services and Credentials...

Select Credentials from the APIs and services menu

 

2. When the Credentials page loads, the API key that your created for your website should be listed. Click on the pencil icon to Edit API key...

Edit API key


3. On the page that loads, find the section called "Website restrictions". Your website domain should be listed here already. Click on ADD AN ITEM...

Add an item


4. In the New Item field that appears type in localhost/* and then click DONE...

Enter the localhost address and click Done


5. Click SAVE...

Click Save


The same Google Maps API key should now work both on your live website and on your local version of TNG on your computer.

Geocoding: Getting Latitudes and Longitudes

There are basically three ways to add latitude and longitude to your Places:

Related Links

  • Maintenance - Places with no maps provides an SQL Report for Places with no latitude and longitude sorted in descending order of event references with links to Admin Places to help geocode