2015-08-28 68 views
1

我試圖用「LongPress事件」向地圖添加註釋。使用LongPress事件創建註釋

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] 

我從我的屏幕上顯示的座標。但我需要地圖上的座標。

我該怎麼做? 有人可以幫我嗎? :)

謝謝。

回答

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); 
     } 
+0

謝謝!作品像一個魅力:) 有沒有可能保存這個註釋?當我重新打開地圖時,此自定義註釋消失。 是否還有可能添加多個註釋並保存它們? – Slade

+0

你是什麼意思「重新打開地圖」(請添加一個代碼片段)。大多數如果你「恢復地圖」,那麼註釋應該仍然存在 – Ando

+0

我很抱歉。我有和我的其他註釋一樣的annotaion-id ... – Slade