2014-06-25 33 views
4

我想在Android SDK中設置自定義圖像註釋,我無法做到。如果我使用代碼創建帶默認圖像的註釋:爲什麼不顯示自定義註釋?

annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_GREEN); 

將顯示註釋。但是,當我使用代碼設置自定義圖像時:

annotation.setImagePath(getActivity().getFilesDir() + "/" + data.getMapImagePath()); 
annotation.setImageSize(64); 

註釋未顯示。圖像路徑中的變量解析爲(例如):"/data/data/com.kolobee.mini/files/stings_chueca.me9d_map.png"

FileOutputStream fos = context.openFileOutput(path, Context.MODE_PRIVATE); 
bitmap.compress(CompressFormat.PNG, 75, fos); 
fos.close(); 

爲什麼不被顯示的註釋:

此圖像被動態地由應用通過創建從一個Bitmap文件png與代碼生成?

+0

自定義圖像不工作在我身邊太。這是我使用的圖像:cl.ly/image/0l0T2n1B3O07(Photoshop生成,64x64,24位透明PNG)SKAnnotation * annotation = [SKAnnotation annotation]; //設置唯一ID //設置位置annotation.imagePath = [[NSBundle mainBundle] pathForResource:@「purpleAlert」ofType:@「png」]; [self.mapView addAnnotation:annotation];沒有運氣。沒有顯示。 –

回答

0

在2.1.0我們已經增加了對使用圖像從資源包&支持擴展的完整路徑圖像的例子 - 在這裏是更新prepareAnnotations代碼:

/** 
* Draws annotations on map 
*/ 
private void prepareAnnotations() { 

    // get the annotation object 
    SKAnnotation annotation1 = new SKAnnotation(); 
    // set unique id used for rendering the annotation 
    annotation1.setUniqueID(10); 
    // set annotation location 
    annotation1.setLocation(new SKCoordinate(-122.4200, 37.7765)); 
    // set minimum zoom level at which the annotation should be visible 
    annotation1.setMininumZoomLevel(5); 
    // set the annotation's type 
    annotation1.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_RED); 
    // render annotation on map 
    mapView.addAnnotation(annotation1); 

    SKAnnotation annotation2 = new SKAnnotation(); 
    annotation2.setUniqueID(11); 
    annotation2.setLocation(new SKCoordinate(-122.410338, 37.769193)); 
    annotation2.setMininumZoomLevel(5); 
    annotation2.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_GREEN); 
    mapView.addAnnotation(annotation2); 

    SKAnnotation annotation3 = new SKAnnotation(); 
    annotation3.setUniqueID(12); 
    annotation3.setLocation(new SKCoordinate(-122.430337, 37.779776)); 
    annotation3.setMininumZoomLevel(5); 
    annotation3.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_BLUE); 
    mapView.addAnnotation(annotation3); 

    // annotation drawn with drawable resource 
    SKAnnotation annotation4 = new SKAnnotation(); 
    annotation4.setUniqueID(13); 
    annotation4.setLocation(new SKCoordinate(-122.425, 37.774)); 
    annotation4.setMininumZoomLevel(5); 
    SKAnnotationView annotationView = new SKAnnotationView(); 
    // set the drawable resource to be rendered as annotation 
    annotationView.setDrawableResourceId(R.drawable.dot_full); 
    // set the size of the annotation (this value must be a power of 2) 
    annotationView.setProperSize(16); 
    annotation4.setAnnotationView(annotationView); 
    mapView.addAnnotation(annotation4); 

    // annotation drawn with image from a local file 
    SKAnnotation annotation5 = new SKAnnotation(); 
    annotation5.setUniqueID(14); 
    annotation5.setLocation(new SKCoordinate(-122.417, 37.772)); 
    annotation5.setMininumZoomLevel(5); 

    // set path to an image whose dimensions are powers of 2 
    // image is selected according to screen density 
    DisplayMetrics metrics = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(metrics); 
    if (metrics.densityDpi < DisplayMetrics.DENSITY_HIGH) { 
     annotation5.setImagePath(app.getMapResourcesDirPath() + "images/dot_blue_medium.png"); 
    } else { 
     annotation5.setImagePath(app.getMapResourcesDirPath() + "images/dot_blue_high.png"); 
    } 
    annotation5.setImageSize(40); 
    mapView.addAnnotation(annotation5); 

    selectedAnnotation = annotation1; 
    // set map zoom level 
    mapView.setZoom(14); 
    // center map on a position 
    mapView.centerMapOnPosition(new SKCoordinate(-122.4200, 37.7765)); 
    updatePopupPosition(); 
} 
+0

我將更新SDK並檢查問題是否已解決。謝謝 :) – eliocs