javascript 浏览器定位
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
#r-result{height:100%;width:20%;float:left;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak="></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<title>GPS转百度</title>
<script>
var point = new BMap.Point(116.331398,39.897445);
//判断手机浏览器是否支持定位
if(navigator.geolocation){
var geolocation = new BMap.Geolocation();//创建定位实例
geolocation.getCurrentPosition(showLocation,{enableHighAccuracy: true});//enableHighAccuracy 要求浏览器获取最佳结果
}else{
map.addControl(new BMap.GeolocationControl());//添加定位控件 支持定位
}
//处理定位后的信息
function showLocation(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){//定位成功
//新建中心点 并将地图中心移动过去
alert("百度:"+r.longitude+","+r.latitude);
}
else {
alert('failed'+this.getStatus());//定位失败
}
}
</script>
</head>
<body>
<div id="allmap"></div>
百度jsapi
</body>
</html>
最新文章
- Hibernate框架之Criteria查询 和注解(重点☆☆☆☆☆,难点☆☆☆)
- yii2 数据库操作(转)
- 解决org.openqa.selenium.WebDriverException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms org.springframework.beans.BeanInstantiation
- FAQ: C++中定义类的对象:用new和不用new有何区别?
- FastJson之有道翻译
- Mybatis 学习-1
- 【英语】Bingo口语笔记(57) - 常见的口语弱读
- angular 输入框实现自定义验证
- Jmeter连接DB2/ORACLE/MYSQL数据库
- MySQL中时间函数NOW()和SYSDATE()的区别
- springboot 出现 Connection refused: connect
- redis 数据结构及应用场景
- 对于react中rredux的理解
- 基于Electron+.NET Core的前后端分离的跨平台桌面应用
- 使用docker搭建数据分析环境
- JavaScript之简易http接口测试工具网页版
- rest framework 源码流程
- kvm虚拟机日常操作命令梳理
- Python基础教程-第3版(文字版) 超清文字-非扫描版 [免积分、免登录]
- 9/252D图的画法