SQL MR: GoogleDrivingDistance

Aster Field Strong
Teradata Employee

This is the first blog edition of the SQL MR Underground.  This is a constant beta blog post and is not supported by the field or by Teradata Aster product support or engineering.  Please use at your own risk.

Overview

GoogleDrivingDistance calculates distance between two geographic locations, as well as the travel time using the Google Maps APIs: Google Distance Matrix, Google Directions, Google Embed. The syntax and example usage are described in the succeeding sections. GoogleDrivingDistance can output the distance, travel time, and a Google Maps URL that can be opened in a browser to display the routes taken by the API to calculate distance and travel time. Note: Workers should be able to access https://maps.googleapis.com in order to retrieve results.

Syntax

SELECT *

FROM GoogleDrivingDistance (

           ON {table_name | view_name | (query)}

           KEY('api_key')

           ORIGIN('origin_column')

           DESTINATION('destination_column')

           [MODE('travel_mode')]

           [AVOID('avoid')]

           [LANGUAGE('language_code')]

           [UNIT('unit_of_measure')]

           [MAP('map_mode')]

);

Arguments:

KEY Required

API Key generated by Google

ORIGIN Required Column to denote as the origin location. This column should not be null.

DESTINATION Required Column to denote as the destination location. This column should not be null.

MODE

Optional

Travel Mode. The following modes are accepted: driving(default), walking, bicycling, transit

AVOID

Optional

Remove paths that go go through the indicated value. The following values are accepted: tollways, highways, ferries.

LANGUAGE Optional Translates output to the specified language, like 'en'(default) or 'es'. Full list of language codes can be found in the Google maps page .https://developers.google.com/maps/faq#languagesupport.

UNIT Optional Possible values are 'metric'(default) and 'imperial'.

MAP Optional

Display mode for the map. The following modes are accepted:

embed - Returns a url that can be embedded into a web page. This url needs to be placed inside an iframe. This provides an interactive map.

static - Returns a url that will display a static image with the route between the two locations plotted in the map.

default - Uses the default url of Google Maps to display the route between two locations.

Example

Example

googdrive.JPG