2016-05-30 39 views
0

我創建一個應用程序與一些註釋。現在我需要處理點擊服裝的註釋。我試圖在每個註釋或mapView上放置點擊事件,但沒有任何接縫可以工作。我曾經嘗試這樣做:點擊IOS上的mapView中的事件不工作在鈦工作室

這是我如何創建我的服裝註釋:

var pins = []; 

var imgTemp = Ti.UI.createImageView({ 
    image : "/images/p_" + keys[j] + ".png" 
}); 

var alturaImg = imgTemp.toBlob().height; 
var larguraImg = imgTemp.toBlob().width; 
var alturaImgNova = deviceHeight * 0.04; 
var fator = alturaImg/alturaImgNova; 
var larguraImgNova = larguraImg/fator; 

var annottion = MapModule.createAnnotation({ 
    latitude : pontos2[keys[j]][i].Lat, 
    longitude : pontos2[keys[j]][i].Long, 
    pincolor : MapModule.ANNOTATION_VIOLET, 
    customView : Ti.UI.createImageView({ 
     height : alturaImgNova, 
     width : larguraImgNova, 
     image : "/images/p_" + keys[j] + ".png" 
    }), 
    draggable : false, 
    id : id 
}); 

pins.push(pins); 
mapview.addAnnotations(pins); 

點擊註釋:

MyAnnotation.addEventListener('click', function() { 
    alert("click"); 
}); 

點擊的MapView:

mapview.addEventListener('click', function() { 
    alert("click"); 
}); 

在android的mapView點擊事件工作正常。問題出在IOS上。

+0

我發現,當我定義 '標題:' 測試」'click事件的作品。問題是我不需要InfoWindow。我也試圖把一個標題和隱藏的信息窗口,但showInfoWindow:false,接縫不工作 –

回答

2

對於IOS,您必須將canShowCallout設置爲false。上的MapView

var annotation = MapModule.createAnnotation({ 
     latitude : annotations[i].latitude, 
     longitude : annotations[i].longitude, 
     myid : i 
    }); 

if (OS_IOS) { 
     annotation.image = "/images/icn_map_location.png"; 
     annotation.canShowCallout = false; 
    } else { 
     annotation.customView = Ti.UI.createLabel({ 
      width : 48, 
      height : 58, 
      backgroundImage : "/images/icn_map_location.png" 
     }); 
    } 

點擊:

創建註釋

mapView.addEventListener("click", myFunction); 
+0

你可以聽到一個例子,請問您的AR如何做?我試圖改變te customView到圖像機器人還沒有解決我的問題。我已經讀過,有必要爲註釋定義一個標題。如果它沒有任何標題,點擊事件不起作用在IOS –

+0

我編輯了我的答案@Manuel_Rodrigues – HamidMly

+0

我試過你把@HamidMly的例子,但問題依然存在。點擊事件只適用於android而不適用於IOS。點擊事件只有在爲註釋定義標題時才起作用。 –