plus maps实时定位

.mapContent {
                position: absolute;
                top: 44px;
                left: 0;
                right: 0;
                bottom: 0;
            }
 <div id="content" class="mapContent"></div>
mui.plusReady(function() {
            var count = 0;
            var marker;
            var map = new plus.maps.Map("content");
            setTimeout(function() {
                userlocation();
            }, 1);
            
            function userlocation() {
            //    alert("18")
            map.getUserLocation(function(state, pos) {
                count++;
                if(0 == state) {

                    if(count == 1) {

                        setTimeout(function() {

                            map.setZoom(17);
                            map.removeOverlay(marker);
                            marker = new plus.maps.Marker(pos);
                            marker.setIcon("img/[email protected]");
                            map.addOverlay(marker);
                        }, 400);
                        map.setCenter(pos);
                        setTimeout(function(e) {

                            userlocation();
                        }, 200);
                    } else {

                        map.removeOverlay(marker);
                        //                            map.setCenter(pos);
                        marker = new plus.maps.Marker(pos);
                        marker.setIcon("img/[email protected]");
                        map.addOverlay(marker);

                        setTimeout(function(e) {
                            //    alert("18-1-2-1")
                            userlocation();
                        }, 5000);

                    }
                } else {
                    //alert("18-2")
                    alert("xxx");
                }
            });
        }
        });

猜你喜欢

转载自www.cnblogs.com/ccllj/p/9638016.html