2012-11-27 4 views
0

내 응용 프로그램의 URL https://github.com/jgilfelt/android-mapviewballoons에 제공된 소스 코드를 사용하고 있습니다. 그것은 URL을 사용하여 이미지를 보여줍니다. 하지만 내 응용 프로그램의 drawable 폴더에서 이미지를로드하도록하려면 어떻게해야합니까?URL이 아닌 드로어 블 폴더의 이미지를 어떻게 추가합니까?

나는 MapView url을 발견했으며 풍선 이미지를 보여줍니다. 하지만 그것은 URL에서 이미지를 보여주고 있습니다. 폴더에서 내 자신의 이미지를 보여주고 싶습니다. 어떻게해야합니까?

코드 :

MapView map = (MapView) findViewById(R.id.mapview); 
    MapController mapController = map.getController(); 
    List<Overlay> overlays = map.getOverlays(); 
    overlays.add(new DrawableMapOverlay(this, point, R.drawable.my_drawable); 
    map.invalidate(); 
Editors 

보고에 있습니다

public class CustomMap extends MapActivity { 

MapView mapView; 
List<Overlay> mapOverlays; 
Drawable drawable; 
Drawable drawable2; 
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay; 
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay2; 

@Override 
    public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mapView = (MapView) findViewById(R.id.mapview); 
    mapView.setBuiltInZoomControls(true); 

    mapOverlays = mapView.getOverlays(); 

    // first overlay 
    drawable = getResources().getDrawable(R.drawable.marker); 
    itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, 
    mapView); 

    GeoPoint point = new GeoPoint((int)(51.5174723*1E6),(int)(-0.0899537*1E6)); 
    CustomOverlayItem overlayItem = new CustomOverlayItem(point, 
    "Tomorrow  Never Dies (1997)", 
      "(M gives Bond his mission in Daimler car)", 
      "http://ia.media-imdb.com/images 
    /M/[email protected]@._V1._SX40_CR0,0,40,54_.jpg"); 
    itemizedOverlay.addOverlay(overlayItem); 

    GeoPoint point2 = new GeoPoint((int)(51.515259*1E6),(int)(-0.086623*1E6)); 
    CustomOverlayItem overlayItem2 = new CustomOverlayItem(point2, 
    "GoldenEye (1995)", 
      "(Interiors Russian defence ministry council chambers in 
    St Petersburg)", 
      "http://ia.media-imdb.com/images 

    M/MV5BMzk2OTg 
    [email protected]@._V1._SX40_CR0,0,40,54_.jpg"); 


    itemizedOverlay.addOverlay(overlayItem2); 

    mapOverlays.add(itemizedOverlay); 

    // second overlay 
    drawable2 = getResources().getDrawable(R.drawable.marker2); 
    itemizedOverlay2 = new CustomItemizedOverlay<CustomOverlayItem> 
    (drawable2, mapView); 

    GeoPoint point3 = new GeoPoint((int)(51.513329*1E6),(int)(-0.08896*1E6)); 
    CustomOverlayItem overlayItem3 = new CustomOverlayItem(point3, "Sliding 
    Doors (1998)", 
      "(interiors)", null); 
    itemizedOverlay2.addOverlay(overlayItem3); 

    GeoPoint point4 = new GeoPoint((int)(51.51738*1E6),(int)(-0.08186*1E6)); 
    CustomOverlayItem overlayItem4 = new CustomOverlayItem(point4, "Mission: 
    Impossible (1996)", 
      "(Ethan & Jim cafe meeting)", 
      "http://ia.media-imdb.com/images 
    /M/MV5BMjAyNjk5Njk0MV 
     [email protected]@._V1._SX40_CR0,0,40,54_.jpg");  
    itemizedOverlay2.addOverlay(overlayItem4); 

    mapOverlays.add(itemizedOverlay2); 

    final MapController mc = mapView.getController(); 
    mc.animateTo(point2); 
    mc.setZoom(16); 

} 

@Override 
protected boolean isRouteDisplayed() { 
    return false; 
} 

    } 
+0

나는 내 자신의 이미지를 제공하고 싶지 않다. –

+0

가능한 [로컬 이미지 파일의 URL을주는 방법] (http://stackoverflow.com/questions/13599828/how-to-give-url-of -local-image-file) – Matthieu

답변

0

이 당신이 당신의지도보기를 가지고 활동에서지도 중첩

import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.Canvas; 
import android.graphics.Point; 

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapView; 
import com.google.android.maps.Overlay; 

public class DrawableMapOverlay extends Overlay { 

    private static final double MAX_TAP_DISTANCE_KM = 3; 
    // Rough approximation - one degree = 50 nautical miles 
    private static final double MAX_TAP_DISTANCE_DEGREES = MAX_TAP_DISTANCE_KM * 0.5399568 * 50; 
    private final GeoPoint geoPoint; 
    private final Context context; 
    private final int drawable; 

    /** 
    * @param context the context in which to display the overlay 
    * @param geoPoint the geographical point where the overlay is located 
    * @param drawable the ID of the desired drawable 
    */ 
    public CamerasMapOverlay(Context context, GeoPoint geoPoint, int drawable) { 
    this.context = context; 
    this.geoPoint = geoPoint; 
    this.drawable = drawable; 
    } 

    @Override 
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { 
    super.draw(canvas, mapView, shadow); 

    // Convert geo coordinates to screen pixels 
    Point screenPoint = new Point(); 
    mapView.getProjection().toPixels(geoPoint, screenPoint); 

    // Read the image 
    Bitmap markerImage = BitmapFactory.decodeResource(context.getResources(), drawable); 

    // Draw it, centered around the given coordinates 
    canvas.drawBitmap(markerImage, 
     screenPoint.x - markerImage.getWidth()/2, 
     screenPoint.y - markerImage.getHeight()/2, null); 
    return true; 
    } 

    @Override 
    public boolean onTap(GeoPoint p, MapView mapView) { 
    // Handle tapping on the overlay here 
    return true; 
    } 
} 

으로 이미지를 추가하는 방법입니다 this 튜토리얼 ..

+0

오버레이 란 무엇입니까 ?? u는 mapOverlays를 의미합니까 ?? –

+0

는 이미지의 평평한 표면에 –

+0

이 코드는 이미지를 표시하지 않습니다. –

0

당신은 할 수 없습니다. 이 R.drawable 때문입니다. * 값은 안드로이드 SDK가 폴더에 새 이미지를 추가하는 동안 만들어집니다. 즉, 앱을 실행하는 동안 생성되지 않으며 새로운 앱을 추가 할 수 없습니다.

대신에 이미지를 forder에 저장하고 방법과 이름을 db에 저장할 수 있습니다.