百度地图

PC端定位不准确  主要应用到移动端

第一、申请百度密钥  很简单的几步就搞定

第二、引入文件

   
   
1
2
3
4
5
 
<!--  -->
< 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 >  


第三、绑定数据到你要显示的输入框内

   
   
1
2
3
4
< 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" />  


第四、控制器中代码

   
   
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
                                             enableHighAccuracy :  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 ( "," ) ;
                                            }
                                       }) ;
                                  } ;
                             }  ]) ;


第五、完整代码如下:(大体思路就是这样!这里做个标记留给以后的自己)

   
   
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
         var  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 ( ) ;  
                           }        
                        } , {  
                             // false  
                             enableHighAccuracy :  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 ;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值