我是角度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位置(lat long)。我正在使用角度js 1.2.23
答案 0 :(得分:0)
正如我所看到的,您应该使用$scope.deal.locations.length;
for for循环而不是$scope.deal[0].locations.length;
但是如果你向JSFiddle提供你的问题会更好。
答案 1 :(得分: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;
}
}
};