如何将谷歌地图的“嵌入地图”链接转换为“分享链接”

whi*_*roi 1 php google-maps

例如,这里是一个测试位置

如果您按“分享”链接 - 有 2 个标签“分享链接”和“嵌入地图

分享链接的数据:

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
Run Code Online (Sandbox Code Playgroud)

嵌入 map的数据:

<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>
Run Code Online (Sandbox Code Playgroud)

我只能访问Embed map的数据。有没有办法可以将Embed map的 iframe 的 src 更改为Share link的 src?有谁知道它使用什么算法?

示例:我想通过 PHP更改"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"

sad*_*lue 5

你需要完整的数据吗?因为如果您将链接结果复制粘贴到浏览器中,这将起作用。

$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
}
Run Code Online (Sandbox Code Playgroud)

不完美,但稍微测试了一下,它奏效了。strlen 是为了防止获取其他变量,因为我不确定它们可能是什么,但模式建议不超过 5 个字符。