【问题标题】:Titanium - Store information in annotationTitanium - 在注释中存储信息
【发布时间】:2011-12-16 06:48:59
【问题描述】:

我正在地图视图上进行多个注释,并且正在打开一个新的详细信息窗口以选择右键。我应该通过标签在 detailWindow 中显示一些信息,并且每个引脚注释要显示的信息是不同的。如何将一些数据存储到引脚注释中?帮助我完成这项工作。提前致谢。

这是我的代码.. 注释创建:

    okBtn.addEventListener("click", function(e) {
        Ti.API.info("Text = " + textField.value);
        mapview.removeAllAnnotations();
        Ti.Geolocation.forwardGeocoder(textField.value, function(e) {
            var annotations = [];
            for(var i = 0; i < 10; i++) {
                var pin = Titanium.Map.createAnnotation({
                    latitude : e.latitude-i,
                    longitude : e.longitude-i,
                    animate : true,
                    pincolor : Titanium.Map.ANNOTATION_RED,
                    rightButton : Titanium.UI.iPhone.SystemButton.DISCLOSURE//'rightButton.png'
                });
                annotations[i] = pin;
                // suppose mapView is your map object
                mapview.addAnnotation(annotations[i]);
            }
            var region = {
                latitude : e.latitude,
                longitude : e.longitude,
                animate : true,
                latitudeDelta : 0.15,
                longitudeDelta : 0.15
            };
            mapview.setLocation(region);
            Ti.API.info(e);
        });
    });
var detailWindow = Ti.UI.createWindow({
    backgroundColor : "#fff",
    navBarHidden : true,
    backgroundImage : 'screen.png'
});
var detailTitle = Ti.UI.createLabel({
    color : '#EC6512',
    font : {
        fontSize : 18,
        fontWeight : 'bold',
        fontFamily : 'Arial'
    },
    left : 12,
    top : 60,
    height : 80,
    width : 300,
    clickName : 'detailTitle',
});
detailWindow.add(detailTitle);

我应该将文本添加到 rightButtonEvent 中的detailTitle 标签。

rightButton 事件:

mapview.addEventListener('click', function(evt) {
    if(evt.clicksource == 'rightButton') {
        Titanium.API.info('Right button clicked');
        navGroup.open(detailWindow);
    };
});

我需要创建一个标签并发送数据以显示在标签中。

【问题讨论】:

  • 请出示该代码,以便我向您推荐解决方案。注释创建和右键单击事件

标签: iphone annotations titanium android-mapview appcelerator


【解决方案1】:

要将数据存储在引脚中,您可以在循环中执行此操作,在注释中设置一个新属性,例如数据,然后在此处设置您的数据数组:{ title, subTitle,...}

for(var i = 0; i < 10; i++) 
{
    var pin = Titanium.Map.createAnnotation({
        latitude : e.latitude-i,
        longitude : e.longitude-i,
    data:data
        animate : true,
        pincolor : Titanium.Map.ANNOTATION_RED,
        rightButton : Titanium.UI.iPhone.SystemButton.DISCLOSURE//'rightButton.png'
    });
    annotations[i] = pin;
    // suppose mapView is your map object
    mapview.addAnnotation(annotations[i]);
}

要在点击事件中访问此数据并同样将其传递到您的窗口:

mapview.addEventListener('click', function(evt) {
    if(evt.clicksource == 'rightButton') {
        Titanium.API.info('Right button clicked');
        var data = evt.annotation.data;
        detailWindow.data = data;
        navGroup.open(detailWindow);
    };
});

【讨论】:

  • 感谢 Zeeshan 的回复。我是 Titanium Studio 的初学者。那么,您能解释一下如何向data 添加数据吗?我现在用更多代码编辑了我的问题。我需要在 detailTitle 标签中显示一个文本。我怎样才能做到这一点?
  • 您需要显示的数据在哪里?你有什么?你会用别针显示它吗?
  • 如果每个注释引脚都有不同的标题,只需使用标题列表创建数据数组,然后将它们添加到 for 循环中,如 data:data[i]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多