通过html5获取地理位置信息
2014-12-30 15:11
489 查看
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>2</title>
</head>
<body>
<center>
<div style="position:fixed;left:40%;top:40%;"><p id="demo"><font size="5">点击这个按钮,获得您的位置:</font></p>
<span id="dis"></span><br>
<input type="button" onclick="getLocation()" style="height:100px;width:200px;" value="试一下"></input>
</div>
</center>
<script src="http://api.map.baidu.com/api?v=1.4" type="text/javascript"></script>
<script>
var x=document.getElementById("demo");
function getLocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}else{
alert("您的浏览器不支持地理定位");
}
}
function showPosition(position){
lat=position.coords.latitude;
lon=position.coords.longitude;
document.getElementById('dis').innerHTML= "你的经度:"+lon+",你的纬度:"+lat;
//var map = new BMap.Map("container"); // 创建Map实例
var point = new BMap.Point(lon, lat); // 创建点坐标
//map.centerAndZoom(point,15); //
//map.enableScrollWheelZoom();
var gc = new BMap.Geocoder();
gc.getLocation(point, function(rs){
var addComp = rs.addressComponents;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street);
});
}
</script>
</body>
</html>
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>2</title>
</head>
<body>
<center>
<div style="position:fixed;left:40%;top:40%;"><p id="demo"><font size="5">点击这个按钮,获得您的位置:</font></p>
<span id="dis"></span><br>
<input type="button" onclick="getLocation()" style="height:100px;width:200px;" value="试一下"></input>
</div>
</center>
<script src="http://api.map.baidu.com/api?v=1.4" type="text/javascript"></script>
<script>
var x=document.getElementById("demo");
function getLocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}else{
alert("您的浏览器不支持地理定位");
}
}
function showPosition(position){
lat=position.coords.latitude;
lon=position.coords.longitude;
document.getElementById('dis').innerHTML= "你的经度:"+lon+",你的纬度:"+lat;
//var map = new BMap.Map("container"); // 创建Map实例
var point = new BMap.Point(lon, lat); // 创建点坐标
//map.centerAndZoom(point,15); //
//map.enableScrollWheelZoom();
var gc = new BMap.Geocoder();
gc.getLocation(point, function(rs){
var addComp = rs.addressComponents;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street);
});
}
</script>
</body>
</html>
相关文章推荐
- IP定位:通过qqwry.bat IP库获取指定IP的地理位置信息
- 通过IP获取地理位置信息的几种方式
- HTML5获取地理位置定位信息
- Android 通过经纬度获取地理位置信息
- Javascript通过腾讯,新浪,谷歌 IP接口获取地理位置信息
- Html5 Geolocation获取地理位置信息
- Android 通过经纬度获取地理位置信息
- html5获取地理位置信息4种方式详解
- 通过GeoIP2分析访问者IP获取地理位置信息
- Html5 Geolocation获取地理位置信息
- html5获取地理位置信息API
- html5 获取地理位置信息
- HTML5之地理信息应用 获取自己的位置
- html5获取地理位置信息
- Android通过百度地图API用Service和Alarm在后台定时获取地理位置信息
- jQuery Mobile + HTML5 获取地理位置信息
- 通过基站信息(LAC,CID)调用google的json接口获取地理位置信息的Java代码
- Html5支持获取用户地理位置信息
- js+html5获取用户地理位置信息并在Google地图上显示的方法