码迷,mamicode.com
首页 > 移动开发 > 详细

webapp定位

时间:2017-12-12 01:00:52      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:width   mes   text   ATX   div   错误   back   rip   message   

<!doctype html>
<html>

    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
        <title>浏览器定位</title>
        <link rel="stylesheet" href="../css/mui.min.css">
        <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.2&key=申请的key"></script>

        <body>
            <header class="mui-bar mui-bar-nav">
                <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
                <h1 class="mui-title">标题</h1>
            </header>
            <div id="tip7" style="margin-top: 5rem;">uuuu</div>
            <div id="tip72" style="margin-top: 5rem;">uuuu</div>
            <script type="text/javascript">
                map = new AMap.Map(‘‘, {
                    resizeEnable: true
                });
                map.plugin(AMap.Geolocation, function() {
                    geolocation = new AMap.Geolocation({
                        enableHighAccuracy: true, //是否使用高精度定位,默认:true
                        timeout: 10000, //超过10秒后停止定位,默认:无穷大
                        buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
                        zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
                        buttonPosition: RB
                    });
                    map.addControl(geolocation);
                    geolocation.getCurrentPosition();
                    AMap.event.addListener(geolocation, complete, onComplete); //返回定位信息
                    AMap.event.addListener(geolocation, error, onError); //返回定位出错信息
                });
                //解析定位结果
                function onComplete(data) {
                    //逆地理编码
                    AMap.service(AMap.Geocoder, function() { //回调函数
                        //实例化Geocoder
                        geocoder = new AMap.Geocoder({
                            city: "010" //城市,默认:“全国”
                        });
                        var lnglatXY = [data.position.getLng(), data.position.getLat()]; //地图上所标点的坐标
                        geocoder.getAddress(lnglatXY, function(status, result) {
                            if(status === complete && result.info === OK) {
                                document.getElementById(tip72).innerHTML = result.regeocode.formattedAddress;
                            } else {
                                //获取地址失败
                                document.getElementById(tip72).innerHTML = "获取地址失败";
                            }
                        });

                    })

                    document.getElementById(tip7).innerHTML = str.join(<br>);
                }
                //解析定位错误信息
                function onError(data) {
                    document.getElementById(tip7).innerHTML = 定位失败 + data.info + "_" + data.message;
                }
            </script>
        </body>
        <script src="../js/mui.min.js"></script>

</html>

 

webapp定位

标签:width   mes   text   ATX   div   错误   back   rip   message   

原文地址:http://www.cnblogs.com/thankyouGod/p/8025697.html

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