我正在寻找一种将经度/纬度转换为相对于地图视图的像素的方法。基本上,我正在寻找类似于Projection.toPixels()的内容,如here所述。
我想要做的是:我需要添加带有背景图像和文本的注释,并且由于默认注释无法实现这样的功能,我必须以某种方式计算它们在地图视图中的位置,相反,添加标签(作为子视图)。
我花了将近一个星期的时间来处理它,没有任何结果。
答案 0 :(得分:0)
注释上有一个属性可用于设置其图像以及单击时显示的标题(将鼠标悬停在其上)。看到这里:
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Map.Annotation-object
这不完全是你想要的吗?
答案 1 :(得分:0)
我没有办法将lat / lng转换为像素,但我确实有办法在注释上获取图像和文本。它是一种“hackish”方式,但它的工作原理。基本上,您所做的就是创建一个包含您想要的任何内容的自定义视图。完成视图设置后,对于注释的图像属性,将其设置为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();
我希望这会有所帮助。