我正在尝试创建一个数组,它将值从本地数据库推送到Titanium中的注释。注释不响应我的数据库的值。我想我在某个地方做了一个男生的错误,但我现在已经盯着自己失明了一段时间。谁能帮我? 非常感激! 欢呼声。
function localdb(){
var db = Ti.Database.install('/my_db/annotations.sqlite', 'Annos');
var row = db.execute('select title, latitude, longitude, type from annotations ');
places = [];
while (row.isValidRow()){
var annotation = Titanium.Map.createAnnotation({
latitude:row.fieldByName('latitude'),
longitude:row.fieldByName('longitude'),
title:row.fieldByName('title'),
subtitle:row.fieldByName('type'),
animate:true,
pincolor: Titanium.Map.ANNOTATION_GREEN
});
places.push(annotation);
mapview.addAnnotation(annotation);
row.next();
}
mapview.annotations = places;
db.close();
}
var mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
height: '100%',
animate:true,
regionFit:true,
userLocation:true,
});
的LocalDB();
win.add(MapView类);
答案 0 :(得分:1)
您需要使用addAnnotations方法传递您创建的注释数组 http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Map.View-method-addAnnotations
var places = [];
while (row.isValidRow()){
var annotation = Titanium.Map.createAnnotation({
latitude:row.fieldByName('latitude'),
longitude:row.fieldByName('longitude'),
title:row.fieldByName('title'),
subtitle:row.fieldByName('type'),
animate:true,
pincolor: Titanium.Map.ANNOTATION_GREEN
});
places.push(annotation);
row.next();
}
// optional mapview.removeAllAnnotations();
mapview.addAnnotations(places);