'Get lat/lon from google maps url ftid (hex)

When using android google maps app share button for a location, it just return a url as intent to other applications like this one:

https: // goo. gl / maps/tkNXzF2krmR2

this is a google short url which is translatable to long url (using goole short url api) to something like this:

http://maps.google.com/?q=Tehran+Province,+Tehran,+Banafsheh+3&ftid=0x3f8dfd04d309f925:0x2867166b05b0bfe6&hl=en&gl=us&shorturl=1

As is clear this url have no pure latitude and longitude values. but it seems that values is behind of ftid parameter in url. which is separated with ":" character.

please help me to extract latitude and longitude values from this hex like format

I'm using PHP language but what others can be help too. i need a function like this one: (this is not work):


    function hextolatlon($hex){
            // Assume hex is a value like 0x1446041F or 0x447D1100
            // Convert to a signed integer
            $h=$hex&0xFF;
            $h=($h>8)&0xFF);
            $h=($h>16)&0xFF);
            $h=($h>24)&0xFF);
            $negative=($h>>31)!=0; // Get the sign
            if($negative){
                $h=~$h;
                $h=$h&0x7FFFFFFF;
                $h++;
            }
            // Convert to degrees and minutes
            $degrees=floor($h/10000000);
            $minutes=$h%10000000;
            // Convert to full degrees
            $degrees+=($minutes/100000.0) / 60.0;
            if($negative)$degrees=-$degrees;
            return $degrees;
        }

to convert 0x3f8dfd04d309f925 to something like 35.74388. many thanks



Solution 1:[1]

Better a late reply than none, I think.

The FTID parameter which you are trying to decrypt is not (necessarily) storing latitude and longitude. If it refers to a Maps place (e. g. a café, fashion store), then the second part of the parameter after the colon refers to the customer ID.

To give a real-world example, the parameter:

!1s0x6ad63fbf56e24c27:0xe665b3308d32f379

can be understood like this

0xe665b3308d32f379  ---hex-to-dec--->  16601872622479930233

and https://google.com/maps?cid=16601872622479930233 will lead to the marked place.

How to extract the coordinates from that? If you only have a few samples, you can do it by hand. Click on the link above, and after 1-2 seconds, Google Maps will refresh the URL in the browser. It now contains the exact coordinates of the place in the !3d and !4d parameter.

If you have many samples and/or want to automatize the process, you have to use the Google Maps API (check for example this link).

What I still haven't figured out is 1) what information the first parameter holds and 2) how to understand the FTID parameter if it leads to an address or a geolocation.

Check also my question posted here for more details.

Solution 2:[2]

function ftid_to_latlong($ftid)
{
    $fetch = curl_request("https://www.google.com/maps?ftid=$ftid");
    preg_match("/\"$ftid\",.*?(\d+\.\d+),(\d+\.\d+)/", $fetch, $geo);
    return [$geo[1], $geo[2]];
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manu CJ
Solution 2 Ehsan Chavoshi