[GIS] Generate GPX file from GoogleMap url

cgoogle-maps-apigpx

I need to create a C# application takes a Google Map Url like this:

https://www.google.it/maps/dir/40.7191523,-74.0123231/40.7087892,-74.010857/40.7082982,-73.9994353/@40.7123687,-74.0111298,15.33z/data=!4m2!4m1!3e2

and export a GPX file.

Can someone tell me how can I achieve this? I don't need the whole script but just the idea or base API methods to call.

Best Answer

You can use Google Maps Directions API (https://developers.google.com/maps/documentation/directions/intro) which returns the route information in JSON or XML format. The route's geometry is encoded in Google's polyline algorithm, see https://developers.google.com/maps/documentation/utilities/polylinealgorithm . Example from Google API Documentation:

... 
<points>a~l~Fjk~uOnzh@vlbBtc~@tsE`vnApw{A`dw@~w\|tNtqf@l{Yd_Fblh@rxo@b}@xxSfytAblk@xxaBeJxlcBb~t@zbh@jc|Bx}C`rv@rw|@rlhA~dVzeo@vrSnc}Axf]fjz@xfFbw~@dz{A~d{A|zOxbrBbdUvpo@`cFp~xBc`Hk@nurDznmFfwMbwz@bbl@lq~@loPpxq@bw_@v|{CbtY~jGqeMb{iF|n\~mbDzeVh_Wr|Efc\x`Ij{kE}mAb~uF{cNd}xBjp]fulBiwJpgg@|kHntyArpb@bijCk_Kv~eGyqTj_|@`uV`k|DcsNdwxAott@r}q@_gc@nu`CnvHx`k@dse@j|p@zpiAp|gEicy@`omFvaErfo@igQxnlApqGze~AsyRzrjAb__@ftyB}pIlo_BflmA~yQftNboWzoAlzp@mz`@|}_@fda@jakEitAn{fB_a]lexClshBtmqAdmY_hLxiZd~XtaBndgC</points>
...

After decoding, conversion to GPX is straightforward. Google allows up to 2,500 free requests per day.