我沒有辦法將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();
我希望這可以幫助了。
感謝您的回覆。我知道這一點。但是,這不是我正在尋找的。我希望文字顯示在圖像的頂部,而不是用戶點擊。此外,我還想在地圖上應用各種其他自定義功能,這肯定不能使用默認註釋完成。 我已經使用前面提到的方法(Projection.toPixels())爲android實現了這樣的應用程序。事情是我找不到類似的鈦。 – George 2012-04-24 06:58:32
看起來像一個小小的黑客,但這呢? http://developer.appcelerator.com/question/135862/convert-longitutelatidute-to-pixels – 2012-04-24 07:43:09
hehe,這是我在appcelerator論壇上發佈的帖子。正如我在那裏回答的那樣,我會盡快嘗試這個人的建議。之後,我會在這裏和這裏發表評論(或希望解決方案)。再次感謝! – George 2012-04-24 08:34:59