Skip to main content
Archived

Extend "Google Maps Polyline Decoder" in GeometryExtractor and GeometryReplacer

Related products:FME Form
  • March 5, 2018
  • 2 replies
  • 52 views

gtitz
Contributor
Forum|alt.badge.img+3

In Google Maps Directions API it is possible to get the waypoints from one coordinate to another coordinate as polyline:

https://developers.google.com/maps/documentation/directions/

Request example:

https://maps.googleapis.com/maps/api/directions/json?origin=46.9745777,15.6211898&destination=46.9752438,15.6144307

Google returns a JSON (because I have requested a JSON) with several information - including waypoints in an encoded format (see line 63, 87 and 101):

{    "geocoded_waypoints" : [       {          "geocoder_status" : "OK",          "place_id" : "EipLaXJjaGJhY2hlciBTdHIuIDk5LTEyMiwgODA4MSwgw5ZzdGVycmVpY2g",          "types" : [ "street_address" ]       },       {          "geocoder_status" : "OK",          "place_id" : "Ej1HdWdnaXR6IEJlcmd3ZWcgNTQsIDgwODEgUGlyY2hpbmcgYW0gVHJhdWJlbmJlcmcsIMOWc3RlcnJlaWNo",          "types" : [ "street_address" ]       }    ],    "routes" : [       {          "bounds" : {             "northeast" : {                "lat" : 46.9774785,                "lng" : 15.6212531             },             "southwest" : {                "lat" : 46.9746073,                "lng" : 15.6144114             }          },          "copyrights" : "Kartendaten © 2018 Google",          "legs" : [             {                "distance" : {                   "text" : "0,8 km",                   "value" : 811                },                "duration" : {                   "text" : "1 Minute",                   "value" : 81                },                "end_address" : "Guggitz Bergweg 54, 8081 Pirching am Traubenberg, Österreich",                "end_location" : {                   "lat" : 46.9752518,                   "lng" : 15.6144114                },                "start_address" : "Kirchbacher Str. 99-122, 8081, Österreich",                "start_location" : {                   "lat" : 46.9746073,                   "lng" : 15.6212531                },                "steps" : [                   {                      "distance" : {                         "text" : "0,4 km",                         "value" : 361                      },                      "duration" : {                         "text" : "1 Minute",                         "value" : 20                      },                      "end_location" : {                         "lat" : 46.9774785,                         "lng" : 15.61923                      },                      "html_instructions" : "Auf u003cbu003eKirchbacher Str.u003c/bu003e/u003cbu003eB73u003c/bu003e nach u003cbu003eNordwestenu003c/bu003e Richtung u003cbu003eGuggitz Bergwegu003c/bu003e starten",                      "polyline" : {                         "points" : "ivu}Gy_j~ASR]RuBh@{@Rg@PGBc@Ra@TUN_@V{AlAY^MPMRQ\\IR"                      },                      "start_location" : {                         "lat" : 46.9746073,                         "lng" : 15.6212531                      },                      "travel_mode" : "DRIVING"                   },                   {                      "distance" : {                         "text" : "0,4 km",                         "value" : 450                      },                      "duration" : {                         "text" : "1 Minute",                         "value" : 61                      },                      "end_location" : {                         "lat" : 46.9752518,                         "lng" : 15.6144114                      },                      "html_instructions" : "u003cbu003eLinksu003c/bu003e abbiegen auf u003cbu003eGuggitz Bergwegu003c/bu003e",                      "maneuver" : "turn-left",                      "polyline" : {                         "points" : "ghv}Gesi~ALh@X`CzAfHp@hBfA|BJPnAzBr@fAPT\\Z"                      },                      "start_location" : {                         "lat" : 46.9774785,                         "lng" : 15.61923                      },                      "travel_mode" : "DRIVING"                   }                ],                "traffic_speed_entry" : [],                "via_waypoint" : []             }          ],          "overview_polyline" : {             "points" : "ivu}Gy_j~ASR]RqD|@o@TeAh@u@f@{AlAY^[d@[p@Lh@X`CzAfHp@hBrAnCnAzBr@fAn@p@"          },          "summary" : "Kirchbacher Str./B73 und Guggitz Bergweg",          "warnings" : [],          "waypoint_order" : []       }    ],    "status" : "OK" }

See the algorithm of Google to encode this, so it should be possible to decode the string when dooing the step in the other direction:

https://developers.google.com/maps/documentation/utilities/polylinealgorithm

On this page is an example of a JavaScript code to decode the polyline string:
https://stackoverflow.com/questions/40877840/google-maps-api-draw-a-route-using-points-of-a-polyline

But unfortunately it's not possible to include the JavaScript library in the JavaScriptCaller:

https://maps.googleapis.com/maps/api/js?libraries=geometry

Because JavaScript seems not to be fully supported by the JavaScriptCaller, it would be great to do the decoding via GeometryExtractor or GeometryReplacer.

There are already a lot of encodings (GeometryExtractor > Parameters > Geometry Encoding):

https://docs.safe.com/fme/2017.1/html/FME_Desktop_Documentation/FME_Transformers/Transformers/geometryextractor.htm

The "Google Maps Polyline Decoder" should be added.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

gtitz
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • March 5, 2018

Sorry, it's a Java code, but I doesn't change the requirement.


gtitz
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • April 26, 2018

I found out, there's a function in GeometryReplacer and GeometryExtractor named "Encoded Polyline", which does exactly this.