1、引入代码
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
//引入cdn
<script type="text/javascript" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
2、使用获取定位
//腾讯位置服务
getPosition() {
let that = this;
that.map = "";
that.posintiondata = {};
//获取定位第一个是自己的key 第二个是名字
const geolocation = new qq.maps.Geolocation("SUJBZ-7A6KX-EUU4H-765XU-LSKKH-6MBOW", "weather");
const options = { timeout: 4000 }; //定位时长
geolocation.getLocation(showPosition, showErr, options);
//定位成功执行的函数
function showPosition(data) {
console.log(data) //获取回的位置数据
}
//定位失败执行的函数
function showErr(data) {
console.log(32131)
}
},
腾讯位置服务 - 立足生态,连接未来 获取key的位置
前端定位组件 | 腾讯位置服务 官方文档