【问题标题】:Convert longitude/latitude to pixels in Appcelerator Titanium在 Appcelerator Titanium 中将经度/纬度转换为像素
【发布时间】:2012-04-23 13:55:51
【问题描述】:

我正在寻找一种将经度/纬度转换为相对于地图视图的像素的方法。基本上,我正在寻找类似于 Projection.toPixels() 的东西,如 here 所述。

我想要做的是以下内容:我需要在其上添加带有背景图像和文本的注释,并且由于默认注释无法实现这样的功能,我必须以某种方式计算它们在地图视图中的位置和改为添加标签(作为子视图)。

我花了将近一个星期的时间来研究它,但没有任何结果。

【问题讨论】:

    标签: google-maps pixel latitude-longitude


    【解决方案1】:

    注解上有一个属性来设置它的图像和一个在点击时显示的标题(悬停在它上面)。看这里:

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

    这不正是您想要的吗?

    【讨论】:

    • 感谢您的回复。我知道这一点。然而,这不是我要找的。我希望文本显示在图像顶部,而不是在用户单击时显示。此外,我还想在地图上应用各种其他自定义功能,当然,使用默认注释无法做到这一点。我已经使用前面提到的方法(Projection.toPixels())实现了这样一个适用于 android 的应用程序。问题是我找不到 Titanium 类似的东西。
    • 看起来像一个小技巧,但是这个呢? developer.appcelerator.com/question/135862/…
    • 呵呵,这是我自己在 appcelerator 论坛上的帖子。正如我在那里回复的那样,我会尽快尝试那个家伙的建议。之后,我会在此处和此处发表评论(或希望是解决方案)。再次感谢!
    【解决方案2】:

    我没有办法将 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();
    

    我希望这会有所帮助。

    【讨论】:

    • 抱歉回复晚了。我刚刚测试了您的建议,但它似乎不起作用。它所做的只是显示默认的红色图钉,而不是您创建的自定义视图。我只在模拟器上试过。任何想法为什么会发生这种情况?
    猜你喜欢
    • 2013-09-21
    • 2011-03-28
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    相关资源
    最近更新 更多