js 獲取定位信息

一、百度帳號 申請一個key http://developer.baidu.com/map/index.php?title=lbscloudjavascript

二、開發下面demo代碼php

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
*{
    height: 100%; //設置高度,否則會顯示不出來
}
</style>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=90E862eb7c58c23ef065bbb74cbd1c9a"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
<script>
$(function(){
navigator.geolocation.getCurrentPosition(translatePoint); //定位
});
function translatePoint(position){
    var currentLat = position.coords.latitude;
    var currentLon = position.coords.longitude;
    var gpsPoint = new BMap.Point(currentLon, currentLat);
    BMap.Convertor.translate(gpsPoint, 0, initMap); //轉換座標
}
function initMap(point){
    //初始化地圖
    map = new BMap.Map("map");
    map.addControl(new BMap.NavigationControl());
    map.addControl(new BMap.ScaleControl());
    map.addControl(new BMap.OverviewMapControl());
    map.centerAndZoom(point, 15);
    map.addOverlay(new BMap.Marker(point))
}
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>

h5特性的高級瀏覽器支持css

相關文章
相關標籤/搜索