PC端定位不准确 主要应用到移动端
第一、申请百度密钥 很简单的几步就搞定
第二、引入文件
第三、绑定数据到你要显示的输入框内
第四、控制器中代码
第五、完整代码如下:(大体思路就是这样!这里做个标记留给以后的自己)
第一、申请百度密钥 很简单的几步就搞定
第二、引入文件
-
12345<!-- 百度地图定位 -->< script src = "http://api.map.baidu.com/components?ak=WUfZTjKPuZ2G5RmgD0Psejv6XOmIEQVQ" > </ script >< script type = "text/javascript" src = "http://api.map.baidu.com/api?v=2.0&ak=WUfZTjKPuZ2G5RmgD0Psejv6XOmIEQVQ" > </ script >
第三、绑定数据到你要显示的输入框内
-
1234完整地址: < input type = "text" ng-model = "all" /> < br >所处城市: < input type = "text" ng-model = "shi" ng-value = "shi" /> < br >所处区域: < input type = "text" ng-model = "qu" ng-value = "qu" /> < br >所处街道: < input type = "text" ng-model = "jiedao" ng-value = "jiedao" />
第四、控制器中代码
-
17181920212223242526272829303132333435363738394041424344454647enableHighAccuracy : true ,// 指定获取地理位置的超时时间,默认不限时,单位为毫秒// timeout: 5000,// 最长有效期(30S),在重复获取地理位置时,此参数指定多久再次获取位置maximumAge : 30 * 1000}) ;} ;$scope . getGeo = function ( ) {var myGeo = new BMap . Geocoder ( ) ;// 根据坐标得到地址描述myGeo . getLocation ( new BMap . Point ( $scope . longitude , $scope . latitude ) ,function ( result ) {if ( result ) {$scope . geoaddress = {'fulladdress' : result . addressComponents . city + result . addressComponents . district + result . addressComponents . street ,'city' : result . addressComponents . city ,'area' : result . addressComponents . district ,'street' : result . addressComponents . street ,} ;$scope . all = result . addressComponents . city + result . addressComponents . district + result . addressComponents . street ;$scope . shi = result . addressComponents . city ;$scope . qu = result . addressComponents . district ;$scope . jiedao = result . addressComponents . street ;alert ( JSON . stringify ( $scope . all ))} else {$scope . showAlert ( "定位失败,地址解析失败" ) ;}}) ;} ;} ]) ;
第五、完整代码如下:(大体思路就是这样!这里做个标记留给以后的自己)
-
20212223242526272829303132333435363738394041424344454647484950515253var geolocation = new BMap . Geolocation ( ) ;geolocation . getCurrentPosition (//获取位置信息成功function ( position ) {if ( this . getStatus ( ) == BMAP_STATUS_SUCCESS ) {$scope . longitude = position . point . lng ;$scope . latitude = position . point . lat ;// 根据坐标得到地址描述$scope . getGeo ( ) ;}} , {// 指示浏览器获取高精度的位置,默认为falseenableHighAccuracy : true ,// 指定获取地理位置的超时时间,默认不限时,单位为毫秒// timeout: 5000,// 最长有效期(30S),在重复获取地理位置时,此参数指定多久再次获取位置maximumAge : 30 * 1000}) ;} ;$scope . getGeo = function ( ) {var myGeo = new BMap . Geocoder ( ) ;// 根据坐标得到地址描述myGeo . getLocation ( new BMap . Point ( $scope . longitude , $scope . latitude ) ,function ( result ) {if ( result ) {$scope . geoaddress = {'fulladdress' : result . addressComponents . city + result . addressComponents . district + result . addressComponents . street ,'city' : result . addressComponents . city ,'area' : result . addressComponents . district ,'street' : result . addressComponents . street ,} ;$scope . all = result . addressComponents . city + result . addressComponents . district + result . addressComponents . street ;
标