0

我是 Angular js 的新手。我正在尝试将基于 id 的 json lat lon 传递给 google api。我的 json 文件结构。

{
 "totalCount":206,
  "deals":[{
       "id":"2",
       "Name":"samir",
       "locations":[{
         "location":"Mundhwa Gaon",
         "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
          "location":"Mundhwa Gaon",
          "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
        ]
      },
      "id":"3",
       "Name":"samir",
       "locations":[{
         "location":"Mundhwa Gaon",
         "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
          "location":"Mundhwa Gaon",
          "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
        ] 
   }]
}

我的角度 js 代码

$http({method: 'GET', url: '/api/v1/asas}).success(function(data) {             
            $scope.deal = data.deals;               


if(data.deals[0].hasOwnProperty("locations") && data.deals[0].locations!=null){                         
                var location=$scope.deal[0].locations[0]['latLon'];
                var locationlatlong=location.split(",");
                $scope.map = {center: {latitude: locationlatlong[0], longitude: locationlatlong[1] }, zoom: 4 }
                $scope.options = {scrollwheel: false};
                var markers = [];
                for (var i = 0; i < $scope.deal[0].locations.length; i++) {
                    markers.push(createmarker(i, $scope.deal[0].locations[i]['location'], $scope.deal[0].locations[i]['latLon'],$scope.deal[0].locations[i]['address']))
                }
                $scope.markers = markers;
                if(badBrowser){
                    $scope.rendermap=false; 

                }else{                      
                    $scope.rendermap=true;      

                }
            }                       


        });

现在它只通过第一个交易 id 位置。我尝试在单击一项交易时进行交易,然后通过该交易ID位置(经纬度)。我正在使用角度 js 1.2.23

4

2 回答 2

0

如我所见,您应该使用$scope.deal.locations.length;in for 循环$scope.deal[0].locations.length;

但是,如果您向 JSFiddle 提供您的问题会更好。

于 2014-09-18T08:25:00.607 回答
0

修复了这个问题。我的代码

$scope.mapcall = function (deals) { 
        $scope.rendermap=false; 
        $scope.rendermapbtn=false;              
        if(deals.locations!=null){                  
            $scope.rendermapbtn=true;                                   
            var location=deals.locations[0]['latLon'];
            var locationlatlong=location.split(",");
            $scope.map = {center: {latitude: locationlatlong[0], longitude: locationlatlong[1] }, zoom: 4 }
            $scope.options = {scrollwheel: false};
            var markers = [];
            for (var i = 0; i < deals.locations.length; i++) {
                markers.push(createmarker(i, deals.locations[i]['location'], deals.locations[i]['latLon'],deals.locations[i]['address']))
            }
            $scope.markers = markers;
            if(badBrowser){
                $scope.rendermapbtn=false;

            }else{                      
                $scope.rendermapbtn=true;   

            }
        }       
    };  
于 2014-09-19T18:26:15.743 回答