whitesiroi
whitesiroi

Reputation: 2843

How to convert Google Map's "Embed map" link to "Share link"

For example, here is a test location.

If you press "Share" link - there is 2 tabs "Share link" and "Embed map"

Share link's data:

https://www.google.com/maps/place/Lexington,+KY/@38.0279975,-84.751751,10z/data=!3m1!4b1!4m5!3m4!1s0x88424429cc9ceb25:0x84f08341908c4fdd!8m2!3d38.0394389!4d-84.5013428

Embed map's data:

<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d402280.8397603136!2d-84.75175098821046!3d38.02799750322416!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x88424429cc9ceb25%3A0x84f08341908c4fdd!2sLexington%2C+KY!5e0!3m2!1sen!2sus!4v1484200230503" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>

I have only access to Embed map's data. Is there a way I can change Embed map's iframe's src to Share link's src? Does anyone know what algorithm it uses?

Example: I want to change "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d402280.8397603136!2d-84.75175098821046!3d38.02799750322416!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x88424429cc9ceb25%3A0x84f08341908c4fdd!2sLexington%2C+KY!5e0!3m2!1sen!2sus!4v1484200230503" TO "https://www.google.com/maps/place/Lexington,+KY/@38.0279975,-84.751751,10z/data=!3m1!4b1!4m5!3m4!1s0x88424429cc9ceb25:0x84f08341908c4fdd!8m2!3d38.0394389!4d-84.5013428" by PHP

Upvotes: 2

Views: 2076

Answers (1)

sadlyblue
sadlyblue

Reputation: 2987

DO you need the whole data? Cause this will work if you copy paste the link result in a browser.

$array = explode('=', $src);
$data = array_filter(explode('!', $array[1]));

$location = $x = $y = '';
foreach($data as $s)
{
    if(substr($s, 0, 2) == "2s" and strlen($s) > 5)
    {
        $location = substr($s, 2);
    }
    elseif(substr($s, 0, 2) == "3d" and strlen($s) > 5)
    {
        $x = substr($s, 2);
    }
    elseif(substr($s, 0, 2) == "2d" and strlen($s) > 5)
    {
        $y = substr($s, 2);
    }
}
if($location != "" and $x != "" and $y != "")
    $result = 'https://www.google.com/maps/place/'.urldecode($location).'/@'.$x.','.$y;
else
{
    // parse error
}

Not perfect, but tested a little and it worked. The strlen is to prevent getting the other variables, because I'm not sure what they could be but the pattern sugests not being longer than 5 chars.

Upvotes: 5

Related Questions