Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何转换谷歌地图';s";“嵌入地图”;链接至;共享链接“;_Php_Google Maps - Fatal编程技术网

Php 如何转换谷歌地图';s";“嵌入地图”;链接至;共享链接“;

Php 如何转换谷歌地图';s";“嵌入地图”;链接至;共享链接“;,php,google-maps,Php,Google Maps,例如,下面是一个例子 如果按“共享链接”按钮,则有两个选项卡“共享链接”和“嵌入地图” 共享链接的数据: 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 <iframe src="https://www.

例如,下面是一个例子

如果按“共享链接”按钮,则有两个选项卡“共享链接”和“嵌入地图

共享链接的数据:

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
<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>
嵌入地图的数据:

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

我只能访问嵌入地图的数据。有没有办法将嵌入地图的iframe的src更改为共享链接的src?有人知道它使用什么算法吗


示例:我想更改
”https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d402280.8397603136!2d-84.75175098821046!3d38.02799750322416!2m3!1f0!2f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x88424429cc9ceb25%3A0x84f08341908c4fdd!2Lexington%2C+KY!5e0!3m2!1sen!2sus!4v1484200230503“
"https://www.google.com/maps/place/Lexington,+KY/@38.0279975,-84.751751,10z/数据=!3m1!4b1!4m5!3m4!1s0x88424429cc9ceb25:0x84f08341908c4fdd!8m2!3d38.0394389!4d-84.5013428“by 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个字符。

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

$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个字符