百度地圖定位

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=eniNDkjbZhqB4Ro7MkEO15p3"></script>
var geolocation = new BMap.Geolocation();
            geolocation.getCurrentPosition(function(r) {
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                   
                  
                    var nowLocation = new BMap.Point(r.point.lng,r.point.lat);

                    var gc = new BMap.Geocoder();    
                    gc.getLocation(nowLocation, function(rs){
                            var addComp = rs.addressComponents;
                            // alert(addComp.city);
                            var strart = addComp.city.indexOf('市');
                            city=addComp.city.substring( 0 ,strart);
                            // city = addComp.city;
                            //設置cookie
                            $.cookie('city',city);
                           console.log(addComp); 
                    });      

                } else {
                    alert('定位失敗,請開啓GPS');
                }
            },
            {
            enableHighAccuracy: true
        })
相關文章
相關標籤/搜索