码迷,mamicode.com
首页 > 其他好文 > 详细

通过百度地图获取当前位置坐标

时间:2016-05-16 12:31:11      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        *
        {
            /*设置高度,不然会显示不出来;*/
            height: 50%;
        }
    </style>
    <script src="/JSLib/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=20b2d52ccd095cac314d65c28fa7fb7e"></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;
            alert("Lat" + currentLat + "   Lon" + currentLon);
            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>

  

通过百度地图获取当前位置坐标

标签:

原文地址:http://www.cnblogs.com/pangjie/p/5497480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!