android - 使用 SKAnnotationView 时如何使 Annotation 的坐标居中

标签 android annotations maps skmaps

我使用 Skobbler SDK 为我的 map View 添加了注释。 它显示完美,但我的问题是我应该如何将我的图像居中到注释的位置,因为发生的事情是我需要点击图像的左上角以便调用 onAnnotationSelected。它应该是被挖掘的中心。

这是我的代码:

private void applyAnnotationOnMapView() {
    annotation = new SKAnnotation();
    annotation.setUniqueID(18);
    annotation.setLocation(new SKCoordinate(121.048099, 14.572744));
    annotation.setMininumZoomLevel(5);
    SKAnnotationView imageView = new SKAnnotationView();
    imageView.setDrawableResourceId(R.drawable.poi_mapv2);
    imageView.setProperSize(32);
    annotation.setAnnotationView(imageView);
    mapView.addAnnotation(annotation);
}

谢谢

最佳答案

创建注解时需要使用offset属性:

试试这个(点击图像时调用 onAnnotationSelected):

 final SKAnnotation annotation = new SKAnnotation(); 
            annotation.setUniqueID(2000); 
            annotation.getLocation().setLongitude(23.593701); 
            annotation.getLocation().setLatitude(46.774959); 

            // center point of the image - tapping on an annotation will 
            // depend on 
            // this value . Also the actual gps coordinates of the 
            // annotation will 
            // be in the center of the image. 
            annotation.getOffset().setX(64); 
            annotation.getOffset().setY(64); 
            annotation.setImagePath(SKMaps.getInstance().getMapInitSettings().getMapResourcesPath() 
                    + "/.Common/ccpmedium_2d_retina.png"); 
            // real size of the image in pixels 
            annotation.setImageSize(128); 

            mapView.addAnnotation(annotation); 

关于android - 使用 SKAnnotationView 时如何使 Annotation 的坐标居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25379407/

相关文章:

Android进程内存映射

language-agnostic - 领土 map 生成

android - 如何在android studio中编写平方根

android - 无法启动 Activity 二进制 XML 文件错误膨胀类,在 Dex 路径列表中找不到类 - Android

android - 如何将 ArrayList<CustomeObject> 从一个 Activity 传递到另一个 Activity ?

java - IDEA 不想使用 javax 中的 NotNull,而是使用 org.jetbrains

Android:无法获取 KML 文件进行解析,然后在 map 上绘制路线

android - 7 个线程/runnable 是不是太多了?是什么让我的应用程序变慢了?

xml - JAXB 2 注释和 XSD

java - AfterCompose 与 Init ZK