<?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>
腾讯地图导航(根据地址)
最新推荐文章于 2024-07-08 23:24:49 发布