There is my code the event listener not working , I wanna open a new window with description of the stores but not open. Here is the code.
mapview.addEventListener('click',function(e) {
mapview.addEventListener('click', function(e){
if (e.clicksource == 'rightView'){
Titanium.include('/tabbar/masinfo.js');
crearinfo(data[evt.index],data[evt.index].categoria);
}
});
and this is the full javascript
////////////////////////////////////////////////////////////////
var win = Titanium.UI.currentWindow; var tab = Titanium.UI.currentTab;
var MapModule = require('ti.map');
var vistasombra= Titanium.UI.createView({ backgroundColor: 'black', opacity:0.4, visible: false });
var loader= Titanium.UI.createActivityIndicator({ message: 'Cargando...', color: 'white' });
loader.hide();
////////////////////////////////////////// Formula Haversine /////////////////////////////////////////////////////////////////////////
function DegToRad(degrees)
{
return degrees * (Math.PI / 180);
};
function Distance(lat1, lon1, lat2, lon2){ var R = 6371; // km
var dLat = DegToRad(lat2 - lat1);
var dLon = DegToRad(lon2 - lon1);
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(DegToRad(lat1)) * Math.cos(DegToRad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
return (Math.round(d));
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function crearMapa(){
var httpClient = Titanium.Network.createHTTPClient();
// Aqu?? me conecto a mi servidor Apache en local
httpClient.open('GET','http://nsm-apps.com/apps/quehay/clients/cercademi.php');
// Enviamos la peticion
httpClient.send();
// Obtenemos los resultados
httpClient.onload = function()
{
data = JSON.parse(this.responseText);
/////////////////////////////////lopp para cargar los datos retornados/////////////////////////////////////////////////////////////////
var dataTotal = (data.length-1);
///////////////////// evento para cargar la nueva ventana con la nota completa ////////////////////////////////////
function getCurrentLocation() {
Ti.Geolocation.preferredProvider = "gps";
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.getCurrentPosition(function(e) {});
//
// Setup Callback Function
//
var locationCallback = function(e) {
if (!e.success || e.error) {
// do whatever error processing you need here
return;
}
// turn off the event listener. It will be turned back on at the next time I call
Titanium.Geolocation.removeEventListener('location', locationCallback);
var result=[];
var longitude = e.coords.longitude;
var latitude = e.coords.latitude;
var altitude = e.coords.altitude;
var heading = e.coords.heading;
var accuracy = e.coords.accuracy;
var speed = e.coords.speed;
var timestamp = e.coords.timestamp;
var altitudeAccuracy = e.coords.altitudeAccuracy;
var mapview = MapModule.createView({
top: 0,
left:0,
right:0,
bottom:0,
region: {latitude:latitude, longitude:longitude,
latitudeDelta:0.05, longitudeDelta:0.05},
animate: true,
userLocation: true
});
var dist;
for(i=0;i< data.length ;i++){
dist=Distance(latitude,longitude,data[i].latitud,data[i].longitud);
var foto = Titanium.UI.createImageView({
image: data[i].logo,
height: 30,
width: 30
});
foto.toImage();
var vistaprueba= Titanium.UI.createView({
height: 30,
width: 30
});
vistaprueba.add(foto);
var prueba= Titanium.UI.createImageView({
image: '/archivos/yes.png',
backgroundColor: 'transparent',
height:30,
width:30
});
var etiqueta = MapModule.createAnnotation({
latitude:data[i].latitud,
longitude:data[i].longitud,
title:data[i].nombre,
subtitle:data[i].slogan,
backgroundColor: 'white',
leftView: vistaprueba,
rightView: prueba
});
if(dist <= 2 ) {
switch(data[i].categoria)
{
case 'quecomprar':
etiqueta.image= '/pins/pincomprar.png';
break;
case 'quecomer':
etiqueta.image= '/pins/pincomer.png';
break;
case 'queturista':
etiqueta.image= '/pins/pinturista.png';
break;
case 'quehacer':
etiqueta.image= '/pins/pinhacer.png';
break;
case 'queevento':
etiqueta.image= '/pins/pinevento.png';
break;
};
mapview.addAnnotation(etiqueta);
}
};
mapview.addEventListener('click',function(e) {
mapview.addEventListener('click', function(e){
if (e.clicksource == 'rightView'){
Titanium.include('/tabbar/masinfo.js');
crearinfo(data[evt.index],data[evt.index].categoria);
}
});
win.add(mapview);
};
Titanium.Geolocation.addEventListener('location', locationCallback);
};
getCurrentLocation();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }; // fin de onload /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Comprobar si ocurre un error
httpClient.onerror = function(e)
{
Ti.API.info("Error");
// llamamos la funci??n de error
error();
};
function error()
{
// Aqu?? mostraremos una alerta del error que nos pueda devolver con createAlertDialog
var alert = Titanium.UI.createAlertDialog(
{
title: 'Conexion',
message: 'Error temporalmente fuera de servicio',
buttonNames: ['OK']
});
alert.show();
}
};
vistasombra.show(); loader.show();
setTimeout(function() {
vistasombra.hide();
loader.hide();
}, 8000);
win.add(vistasombra); win.add(loader); crearMapa();