gpt4 book ai didi

php - 如何将 Google map "Embed map"链接转换为 "Share link"

转载 作者:行者123 更新时间:2023-12-03 09:12:07 27 4
gpt4 key购买 nike

例如,这是 test location .

如果您按“分享”链接 - 有 2 个选项卡“分享链接”和“嵌入 map

分享链接的数据:

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

嵌入 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>

我只能访问嵌入 map 的数据。有没有办法将嵌入 map 的iframe的src更改为共享链接的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!2s列克星敦%2C+KY!5e0!3m2!1sen!2sus!4v1484200230 503""https ://www.google.com/maps/place/列克星敦,+KY/@38.0279975,-84.751751,10z/data=!3m1!4b1!4m5!3m4!1s0x88424429cc9ceb25:0x84f08341908c4fdd!8m2!3d38.0394389!4d -84.5013428 “ 通过 PHP

最佳答案

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

$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
}

并不完美,但经过一些测试,它起作用了。 strlen 是为了防止获取其他变量,因为我不确定它们可能是什么,但模式建议长度不超过 5 个字符。

关于php - 如何将 Google map "Embed map"链接转换为 "Share link",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41606059/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com