2012-04-23 76 views
2

我正在尋找一種方法將longitute/latitude轉換爲相對於Map視圖的像素。基本上,我正在尋找類似於Projection.toPixels()的東西,如here所述。將加速器/ latidute轉換爲Appcelerator Titanium中的像素

我想要做的是以下內容:我需要添加帶有背景圖片和文本的註釋,並且由於這種功能對於默認註釋是不可能的,所以我必須以某種方式計算它們在Map視圖中的位置並添加標籤(作爲兒童的意見),而不是。

我花了差不多一個星期的時間對它進行研究,沒有任何結果。任何解決方案/建議都值得歡迎 提前謝謝!

回答

0

註釋上有一個屬性,用於設置其圖像以及單擊時顯示的標題(將鼠標懸停在其上)。在這裏看到:

http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Map.Annotation-object

這不正是你想要的?

+0

感謝您的回覆。我知道這一點。但是,這不是我正在尋找的。我希望文字顯示在圖像的頂部,而不是用戶點擊。此外,我還想在地圖上應用各種其他自定義功能,這肯定不能使用默認註釋完成。 我已經使用前面提到的方法(Projection.toPixels())爲android實現了這樣的應用程序。事情是我找不到類似的鈦。 – George 2012-04-24 06:58:32

+0

看起來像一個小小的黑客,但這呢? http://developer.appcelerator.com/question/135862/convert-longitutelatidute-to-pixels – 2012-04-24 07:43:09

+0

hehe,這是我在appcelerator論壇上發佈的帖子。正如我在那裏回答的那樣,我會盡快嘗試這個人的建議。之後,我會在這裏和這裏發表評論(或希望解決方案)。再次感謝! – George 2012-04-24 08:34:59

0

我沒有辦法將lat/lng轉換爲像素,但我確實有辦法在註釋中獲取圖像和文本。這是一種「冒險」的方式,但它的工作原理。基本上,你所做的就是用你想要的任何東西創建一個自定義視圖。在您完成視圖設置後,對於註釋的圖像屬性,將其設置爲yourCustomView.toImage()。

下面是一個例子:

//Setup device size variables 
var deviceWidth = Ti.Platform.displayCaps.platformWidth; 
var deviceHeight = Ti.Platform.displayCaps.platformHeight; 

//Create a new window 
var w = Ti.UI.createWindow({ 
    width:deviceWidth, 
    height:deviceHeight 
}) 

//Create view for annotation 
var annotationView = Ti.UI.createView({ 
    width:50, 
    height:50, 
    backgroundImage:'http://www.insanedonkey.com/images/bubble.png', 
}) 

//Add text to the annotation view 
var annotationText = Ti.UI.createLabel({ 
    width:'auto', 
    height:'auto', 
    text:'785k', 
    font:{fontSize:12,fontWeight:'bold'}, 
    color:'#fff', 
}) 
annotationView.add(annotationText); 

//Create a new annotation 
var newAnnotation = Titanium.Map.createAnnotation({ 
    latitude:36.134513, 
    longitude:-80.659690, 
    animate:true, 
    image:annotationView.toImage() //Convert the annotationView to an image blob 
}); 


var mapview = Titanium.Map.createView({ 
    region:{latitude:36.134513, longitude:-80.659690, latitudeDelta:0.0009,  longitudeDelta:0.0009}, 
    animate:true, 
    regionFit:true, 
    userLocation:true, 
    annotations:[newAnnotation], 
    mapType:Titanium.Map.STANDARD_TYPE, 
    width:2000, 
    height:2000 

}); 

//Add the mapview to the window 
w.add(mapview); 

//Open the window 
w.open(); 

我希望這可以幫助了。

+0

對不起,延遲迴復。我只是測試了你的建議,但它似乎並不奏效。它所做的只是顯示默認的紅色別針,而不是您創建的自定義視圖。我只在模擬器上試過。任何想法,爲什麼這可能發生? – George 2012-06-06 07:40:15

相關問題