0

私はAngular jsが初めてです。IDに基づいてjsonの緯度経度を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"
          },
        ] 
   }]
}

私のAngular 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の場所(緯度経度)が渡されます。私はAngular 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 に答える