私は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を使用しています