doudu7626 2017-01-12 05:57
浏览 124
已采纳

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

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

  • 写回答

1条回答 默认 最新

  • duan0414 2017-02-09 14:09
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元