首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角JS地理定位城市

角JS地理定位城市
EN

Stack Overflow用户
提问于 2015-01-26 08:01:46
回答 1查看 1.3K关注 0票数 0

我在app.js中有下面的代码。我想捕捉$scope.city变量中的位置城市。我已经宣布了城市外的地理代码功能,但是城市并没有得到任何价值。需要你的帮助

代码语言:javascript
复制
// code as below 

app.controller('ydmoreCtrl', function($scope, $timeout, $ionicModal, $ionicSideMenuDelegate, Categories) {
 (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position){

      var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
      var geocoder = new google.maps.Geocoder();  

        var city; 

            geocoder.geocode({'latLng': latlng}, function(results, status)
                    {
                        if (status == google.maps.GeocoderStatus.OK)
                         {
                                if (results[0])
                                {
                                    var add= results[0].formatted_address ;
                                    var  value=add.split(",");

                                    count=value.length;
                                    country=value[count-1];
                                    state=value[count-2];
                                    city=value[count-3];
                                    callback(latlng);
                           //         alert(city);
                                }
                                else 
                                {
                          alert("address not found");
                                }
                        }
                    });

      $scope.$apply(function(){

            $scope.city = "Pune";


      });
    });
  }
/*



*/
EN

回答 1

Stack Overflow用户

发布于 2015-01-26 08:20:20

你可以试着打电话

$scope.apply()

在城市被设置为

$scope.city

内部到geocoder.geocode调用

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28146449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档