百度地图定位

<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

        })

 

你可能感兴趣的:(百度地图)