腾讯地图导航(根据地址)

<?php
$address = '北京市朝阳区焦化厂地铁站';
if (isset($_GET['address'])) {
    $address = $_GET['address'];
}
//百度key
$bd_key = '自己的百度key';
//腾讯key 需要在https://lbs.qq.com/console/mykey.html处配置ip白名单
$tx_key = '自己的腾讯key';

//百度地址转坐标
$bd_url = "http://api.map.baidu.com/geocoder/v2/?output=json&ak={$bd_key}&address={$address}";
$bd_info = file_get_contents($bd_url);
$bd_xy = json_decode($bd_info, true)['result']['location'];

//百度坐标换取腾讯坐标
$tx_url = "https://apis.map.qq.com/ws/coord/v1/translate?locations={$bd_xy['lat']},{$bd_xy['lng']}&type=3&key={$tx_key}";
$tx_info = file_get_contents($tx_url);
$tx_xy = json_decode($tx_info, true)['locations'][0];

//跳转URL
$url = "http://apis.map.qq.com/uri/v1/marker?marker=coord:{$tx_xy['lat']},{$tx_xy['lng']};title:位置;addr:{$address}";
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <title>腾讯地图导航</title>
    <style>
        body{
            margin:0;
            padding:0;
            overflow-y:hidden
        }
    </style>
</head>
<body>
<!--onload 自动适应宽高-->
<iframe src="<?=$url?>" id="frame" frameborder="0" onload="this.height = window.screen.availHeight * 0.9;this.width = window.screen.availWidth"></iframe>
</body>
</html>
<script>
    //自动适应全全屏
//    window.onload = function () {
//        var frame = document.getElementById('frame');
//        frame.height = window.screen.availHeight;
//    };
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值