0

I am new in angular js .I am trying to pass my json lat lon data in to goole api .My json file structure

{
 "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"
          },
        ]

   }]
}

My angular js code

$http({method: 'GET', url: '/api/v1/asas}).success(function(data) {             
            $scope.deal = data.deals;               
            if(data.deals.hasOwnProperty("locations") && data.deals.locations!=null){           

                var location=$scope.deal.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.locations.length; i++) {
                    markers.push(createmarker(i, $scope.deal.locations[i]['location'], $scope.deal.locations[i]['latLon'],$scope.deal.locations[i]['address']))
                }
                $scope.markers = markers;
                if(badBrowser){
                    $scope.rendermap=false; 

                }else{                      
                    $scope.rendermap=true;      

                }
            }                               
        });

But my if condition not working because of they don't get value . I am using angular js 1.2.23

1
  • Are you sure success is even being called? Commented Sep 18, 2014 at 5:44

2 Answers 2

1

The deals is an array where each element of the array is an object containing the fields for one deal, you should use a loop over data.deals[i] to access the data for the i-th deal.

Sign up to request clarification or add additional context in comments.

Comments

1

Your if condition is checking if the deals array has a property of "locations," which it does not. The first object in the deals array has a property of "locations." You would either want to iterate over the deals array and run each item through your condition:

data.deals.forEach(function(deal) {
  if (deal.locations)...

or just check the first item:

if(data.deals[0].locations ...

1 Comment

Is it possible to pass latlon base on deal "id" ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.