Retrieve DirectionsResult data from a Google Maps URL

Currently, I am developing an updated tool that can transform Google Maps directions into GPX files. The initial version of this tool is performing quite well: it utilizes the Google Maps Javascript API (v3) to showcase a map on the website, allowing users to plan their route using familiar methods similar to those on the main Google Maps page.

An important feature of this site (and the functionality in previous versions prior to Google making changes to their undocumented &output=kml interface!) involves users mapping out their routes on the main Google Maps platform and saving the link for future reference. By pasting this link onto the site, the tool would then convert the planned route into a GPX file.

I am curious if there is a method to extract a DirectionsResult from a Google Maps URL or the main Google Maps page (potentially achieved by submitting the URL to the Google Maps API for analysis or utilizing a bookmarklet on the webpage itself).

Answer №1

The DirectionsResult object is not directly accessible through the link provided on maps.google.com. However, the endpoints and any waypoints specified should yield the same result when given the same input.


Update

Below is a breakdown of the URL from the supplied link, with 24 total waypoints (including 2 end points). The 'geocode' parameter remains somewhat mysterious.

https://maps.google.co.uk/maps?
saddr=Unknown+road  //1
daddr=51.59782,-2.08838 //2
+to:51.74885,-1.94076   //3
+to:51.89255,-1.87129   //4
+to:51.82571,-1.79752   //5
+to:B4020   //6
+to:51.8183,-1.41985    //7
+to:51.72228,-1.43255   //8
+to:51.6239798,-1.3071767   //9
+to:B4001   //10
+to:51.34501,-1.34062   //11
+to:51.35822,-1.12071   //12
+to:51.31526,-1.02412   //13
+to:51.08784,-1.62069   //14
+to:51.29048,-1.73004   //15
+to:51.21761,-1.98589   //16
+to:51.397,-2.13542 //17
+to:Gloucester+Rd%2FA46 //18
+to:51.69001,-2.22161   //19
+to:51.81753,-2.07376   //20
+to:Southam+Ln  //21
+to:52.06075,-1.95706   //22
+to:52.1244,-1.64775    //23
+to:Unknown+road    //24

hl=en
sll=51.421477,-1.238708
sspn=0.804988,2.425232
geocode=Fe3uEwMd_znk_w%3BFfxREwMdRCLg_ylHpOCHwW1xSDHRnVfMI4sNEw%3BFfKfFQMd6GLi_ymv2fIl5RVxSDFAVssIXhupMA%3BFUbRFwMdRnLj_yk75kbkvCNxSDHw_q6FJ4sNEw%3BFS7MFgMdcJLk_ykD5mQuJTtxSDHgWC3MI4sNEw%3BFdYZFgMd7WHn_w%3BFTyvFgMdtlXq_ymvJFBAac52SDFgrE_MI4sNEw%3BFSg4FQMdGiTq_ymp-yJAfMl2SDGhNuPMI4sNEw%3BFSu4EwMd2A3s_ylFwdt-trl2SDF0LAm28EHw6A%3BFZq5EgMdyvfo_w%3BFXJ2DwMdNIvr_yn381tpGqh2SDHyCAjGbJ6ylw%3B...
...and so on

hl=en
sll=51.421477,-1.238708
sspn=0.804988,2.425232
geocode=... //this continues further

mra=dpe
mrsp=11
sz=9
via=1,2,3,4,6,7,8,10,11,12,13,14,15,16,18,19,21,22
t=m
z=8

To gain a better understanding of map parameters, you can refer to this resource:

Answer №2

Not every route point is guaranteed to be present in the URL of the new Google Maps, especially with shortened URLs.

Some time ago, I developed a tool that can transform the new Google Maps format into a gpx file.

Check it out here!

This tool is also capable of providing a JSON response.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to execute a REST call in JavaScript without utilizing JSON?

(I must confess, this question may show my lack of knowledge) I have a basic webpage that consists of a button and a label. My goal is to trigger a REST call to a different domain when the button is clicked (cross-domain, I am aware) and then display the ...

The function you are trying to use is not a valid jQuery function

Although I've come across this issue in previous posts, none of the solutions worked for me and it's really frustrating. I'm a newbie to javascript and I'm sure the answer is probably simple. I'm attempting to incorporate the rapt ...

A reliable approach for dynamically altering SVG graphics

It seems like IE10 does not support CSS transformations for SVGs, only attribute transformations. Here is an example: <svg><rect id="myrect" width="200" height="200"></rect></svg> setTimeout(function() { var r = document.getE ...

Making an AJAX call to a PHP script to add data

Could you assist me in understanding why my code is resulting in a double insert? I have a JavaScript function that makes an AJAX request to a save.php file to insert data into a database. However, each time I submit it, it performs the insertion twice, al ...

The countdown feature is failing to update despite using the SetInterval function

My goal is to develop a countdown application using Atlassian Forge that takes a date input and initiates the countdown based on the current date. For instance, if I input "After 3 days from now," I am expecting the result to continuously update every seco ...

Utilizing jQuery for seamless communication between parent and child iFrame windows

On my webpage, there is an iFrame containing a table where I want to add a click event to the rows. The challenge is retrieving the selected row within the iFrame from the parent window. The goal is to define a class for a clicked table row like this: $( ...

The Journey of React Native Routing

When building my React Native application, I encountered a challenge with creating a Footer and Tab menu that should only be displayed on certain screens. If I define them within the NavigationContainer, they apply to all screens uniformly. How can I sep ...

There is no way to convert a strongly typed object into an observable object using MobX

I have been utilizing the MobX library in conjunction with ReactJS, and it has integrated quite smoothly. Currently, I am working with an observable array structured as follows: @observable items = []; When I add an object in the following manner, everyt ...

Unable to load more than one controller in a single partial view using AngularJS

I am having trouble loading a second controller to populate a select in my view. Despite my efforts, it just won't cooperate. This is the code snippet I'm using: app.js (function() { 'use strict'; angular .module('app.lazylo ...

Updating lists using PHP and Ajax: a dynamic approach

I am currently using a chat service that relies on polling every 20 seconds for new user data in the chat room. I am looking to improve this process by only downloading information for new users who have just joined, rather than re-downloading old data f ...

How can I use regular expressions to validate one-letter domain names?

I am in the process of developing a validation rule for my C# MVC Model using Regex. [RegularExpression(@"(\w[-._+\w]*\w@\w{1,}.\w{2,3})", ErrorMessage = "* Email Address: Please enter a valid Email Address.")] public virtual stri ...

Checking for the presence of a specific function in a file using unit testing

I am curious if there is a possible way to utilize mocha and chai in order to test for the presence of a specific piece of code, such as a function like this: myfunction(arg1) { ...... } If the code has been implemented, then the test should return t ...

How can Reactjs access a configuration file?

I am struggling to find a solution for reading a properties file in reactJS. I have come across the "properties-reader" module but I can't figure out how to make the require function work. Is there an easier way? For instance, import React, { Com ...

Creating internal utility functions in Angular without exporting them as part of the module can be achieved by following a

Currently, I'm in the process of creating an angular module called MyModule. This module includes several sub-modules. angular.module('MyModule', [ 'MyModule.SubModule1', 'MyModule.SubModule2', 'MyModule.SubMo ...

Encountering a problem with GraphQL API fetching in Next.js: receiving the error message "React functionality 'useContext' is not supported in this environment."

Currently, I have developed a Next.js 14.2.3 application with a GraphQL API endpoint (which I replaced with localhost for StackOverflow). For data fetching, I am utilizing "@apollo/client": "^3.10.3" and "graphql": "^16.8.1". The product page path has been ...

The function signature '() => void' cannot be assigned to a variable of type 'string'

Encountering an issue in Typescript where I am attempting to comprehend the declaration of src={close} inside ItemProps{}. The error message received reads: Type '() => void' is not assignable to type 'string'. Regrettably, I am un ...

Is Angular 4 failing to set headers properly or is Express.js searching in the wrong place?

When interacting with an Express.js API, I encountered a issue regarding the handling of auth tokens. The problem arose when sending the token in the request headers using Angular 4 compared to Postman. In Postman, setting the header named 'Authorizat ...

How to export HTML table information to Excel using JQuery and display a Save As dialog box

This script has been an absolute lifesaver for my web application. Huge thanks to sampopes for providing the solution on this specific thread. function exportToExcel() { var tab_text="<table border='2px'><tr bgcolor='#87AFC6& ...

Error: Unable to use map function on users .. cannot perform mapping on functions

Initially, the map function in my code was working fine. However, suddenly an error started appearing when I included the users.map line. Surprisingly, if I comment out that line, the code works perfectly again. Even more strangely, if I uncomment it, ev ...

Material UI Appbar is throwing an error with an invalid hook call

For my project, I needed to create a simple app bar, so I decided to use the code provided on the Material UI website. Here is the component's code that I used: import React from 'react'; import { fade, makeStyles } from '@material-ui/c ...