使用LongPress事件创建注释

时间:2015-08-28 12:44:05

标签: android skmaps

我尝试使用" LongPress-event"在地图中添加注释。

public void OnLongPress(SKScreenPoint point)
{
    SKCoordinate point1 = new SKCoordinate(point.GetX(), point.GetY());

    SKAnnotation anno1 = new SKAnnotation(10);
    anno1.Location = point1;
    anno1.MininumZoomLevel = 10;
    anno1.AnnotationType = SKAnnotation.SkAnnotationTypeBlue;

    _mapView.AddAnnotation(anno1, SKAnimationSettings.AnimationNone);

    System.Console.WriteLine(point1);
    System.Console.WriteLine(point);
    System.Console.WriteLine(anno1); 
}

从Console.WriteLines我收到以下消息:

[540.9993896484375,1049.2178955078125]

SKScreenPoint [x=540.9994, y=1049.2179]

SKAnnotation [uniqueID=10, location=[540.9993896484375,1049.2178955078125], imagePath=null, imageSize=192, annotationType=33, mininumZoomLevel=10, offset=SKScreenPoint [x=0.0, y=0.0], annotationView=null]

我从屏幕显示中获取坐标。但我需要地图上的坐标。

我该怎么做? 有谁可以帮助我吗? :)

感谢。

1 个答案:

答案 0 :(得分:0)

您需要通过反向地理编码将屏幕点转换为“坐标”:

  public void onLongPress(SKScreenPoint point) {
            SKCoordinate poiCoordinates = mapView.pointToCoordinate(point);
            final SKSearchResult place = SKReverseGeocoderManager
                    .getInstance().reverseGeocodePosition(poiCoordinates);

            SKAnnotation annotation = new SKAnnotation(GREEN_PIN_ICON_ID);

            annotation.setUniqueID(GREEN_PIN_ICON_ID);
            annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_GREEN);


            annotation.setLocation(place.getLocation());
            annotation.setMininumZoomLevel(5);
            mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE);
        }