Issue
I am making multiple annotations on a mapview and I am opening a new detailWindow for the right button selection. I should show some information in the detailWindow via labels and the information to be shown are different for each pin annotation. How could I store some data to the pin annotation? Help me to make this work. Thanks in advance.
This is my code.. Annotation creation:
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);
I should add the text to the detailTitle
label in the rightButtonEvent.
rightButton event:
mapview.addEventListener('click', function(evt) {
if(evt.clicksource == 'rightButton') {
Titanium.API.info('Right button clicked');
navGroup.open(detailWindow);
};
});
I need to create a label and send a data to display in the label.
Solution
To store data in the pin you can do this in your loop, set a new property say data in annotation, and set your data array there say : { 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]);
}
To acces this data in click event and similarly pass it to your window:
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);
};
});
Answered By - Muhammad Zeeshan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.