안드로이드 개발 질문/답변
(글 수 45,052)
package ex0731.exam;
import java.io.FileOutputStream; import java.io.IOException; import java.util.List;
import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.Canvas; import android.os.Bundle; import android.widget.Toast;
import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.google.android.maps.MyLocationOverlay; import com.google.android.maps.Overlay;
public class OverlayLocation extends MapActivity {
MapView mMap;
MyLocationOverlay2 mLocation;
protected boolean isRouteDisplayed() {
return false;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_mapviewtest);
mMap = (MapView)findViewById(R.id.mapview); MapController mapControl = mMap.getController(); mapControl.setZoom(13); mMap.setBuiltInZoomControls(true);
GeoPoint pt = new GeoPoint(37881311, 127729968); mapControl.setCenter(pt);
mLocation = new MyLocationOverlay2(this, mMap); List<Overlay> overlays = mMap.getOverlays(); overlays.add(mLocation);
mLocation.runOnFirstFix(new Runnable() {
public void run() {
mMap.getController().animateTo(mLocation.getMyLocation());
}
});
}
public void onResume() {
super.onResume();
mLocation.enableMyLocation();
mLocation.enableCompass();
}
public void onPause() {
super.onPause();
mLocation.disableMyLocation();
mLocation.disableCompass();
}
class MyLocationOverlay2 extends MyLocationOverlay {
public MyLocationOverlay2(Context context, MapView mapView) {
super(context, mapView);
}
//현재위치를 탭했을때 호출됨.
protected boolean dispatchTap() {
Toast.makeText(OverlayLocation.this, "여기가 현재 위치입니다.",
Toast.LENGTH_SHORT).show();
return false;
}
}
Bitmap bitmap = Bitmap.createBitmap(400, 600,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
mapView.draw(canvas); // <===========================요기서 오류~
try {
FileOutputStream fos = this.openFileOutput("test.png", Context.MODE_WORLD_WRITEABLE);
bitmap.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
위에 map.View.draw(canvas); <== 요기에서 에러가 나는데 왜그런지 고수님들 도와주세용~~




mapView.draw(canvas); << 요기 오류나느건...
mapViwe라는 변수가 없기 때문인 것 같습니다.
위에도 mapView라는 변수가 선언이 아니되었구...
MyLocationOverlay2 클래스에서도 mapView가 인수로 넘어오지 않기때문에..
없는 변수를 사용하신게 아닌지?