当我从google map api中的json数据访问值并在MarkerWithLabel的帮助下添加标记时,labelContent:building.Post-completion。但是当我运行这段代码时,它说,ReferenceError:未定义完成,但我的json数据有以下类型。我认为关于完成后的字符存在一个问题,它无法读取单个句子。但是有一个与之相关的值。
var activity_status = [{"Completion": 0, "Pipeline": 0, "Implementation": 5, "country": "MYANMAR", "Post-completion": 138, "Cancelled": 0},
{"Completion": 0, "Pipeline": 0, "Implementation": 0, "country": "Bahrain", "Post-completion": 0, "Cancelled": 0},
{"Completion": 0, "Pipeline": 0, "Implementation": 0, "country": "ZIMBABWE", "Post-completion": 1, "Cancelled": 0},
{"Completion": 0, "Pipeline": 0, "Implementation": 12, "country": "MONGOLIA", "Post-completion": 34, "Cancelled": 0},{}];
for(var j= 0; j < activity_status.length; j++) {
(function(i) {
var building = activity_status[i];
geocoder.geocode({'address':building.country}, function(results,status){
if(status == google.maps.GeocoderStatus.OK){
var marker = new MarkerWithLabel({
position:new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng()),
title:building.country,
map:map,
labelContent:building.Post-completion,
labelAnchor:new google.maps.Point(6,22),
labelClass:"labels",
labelInBackground:false,
icon:"circle2.png"
});
console.log(building.country)
}
else{
console.log("Geocode was not succcessful for the following reason:" + status);
}
});
})(j);
答案 0 :(得分:1)
像对阵阵一样访问它。 building['Post-completion']