1 Star 1 Fork 0

hello古城 / 地理定位

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
原生js百度定位.html 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
hello古城 提交于 2021-09-09 10:58 . update 原生js百度定位.html.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" readonly id="address" />
<button onclick="position()">点击定位</button>
</body>
<script src="http://api.map.baidu.com/api?v=2.0&ak=【百度官网申请的密匙】"></script>
<script>
function position(){
var LocationCity; //定位地址
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function getinfo(position){
var city = position.address.city; //获取城市信息
var province = position.address.province; //获取省份信息
var district = position.address.district; //获取县或区信息
LocationCity = province+" "+city+" "+district; //拼接赋值地址
alert(LocationCity);
document.getElementById('address').value = LocationCity;
}, function(e) {
LocationCity = "定位失败"
}, {provider: 'baidu'});
}
</script>
</html>
JavaScript
1
https://gitee.com/hellogucheng/geographic-location.git
git@gitee.com:hellogucheng/geographic-location.git
hellogucheng
geographic-location
地理定位
master

搜索帮助