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

navigator和地理定位

时间:2018-01-12 19:45:19      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:padding   erro   har   new   rac   post   oom   center   enter   

<!DOCTYPE html>
<html>
<head>
    <meta name="author" content="Yeeku.H.Lee(CrazyIt.org)" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title> 在地图上定位 </title>
    <style type="text/css">
        html { height: 100% }
        body { height: 100%; margin: 0px; padding: 0px }
        #container { height: 100%; width:100%}
    </style>    
    <script type="text/javascript"
        src="http://webapi.amap.com/maps?v=1.3&key=64620d4e376822f07d4fc16f5118b6f9">
    </script>
    <script type="text/javascript">
    function initialize() 
    {
        navigator.geolocation.getCurrentPosition(function(position)
        {
            // 获取浏览器提供的地理位置信息
            var lnglat = [position.coords.longitude, 
                position.coords.latitude];
            // 创建高德地图,指定把地图显示到container元素上
            var map = new AMap.Map(container,{
                resizeEnable: true,
                zoom: 16,
                center: lnglat
            });
            //    构建显示位置的信息窗口
            var infoWindow = new AMap.InfoWindow({
                content: "我在这里<br>郭薇薇"
            });
            // 打开信息窗口
            infoWindow.open(map, lnglat);
        },
        function(error){alert("您的浏览器没有提供地理位置信息!");}
        ,
        {
            enableHighAccuracy:true,
            maximumAge:1000
        });
    }
    </script>
</head>
<body onload="initialize();">
    <div id="container"></div>
</body>
</html>

 

navigator和地理定位

标签:padding   erro   har   new   rac   post   oom   center   enter   

原文地址:https://www.cnblogs.com/zsszss/p/8277304.html

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