嗨,我是 Android 编程和 Eclipse 的新手。我在以下程序中遇到错误“无法解析 MapView 或不是字段”:
import java.util.List;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.location.Location;
import android.os.Bundle;
import android.view.MotionEvent;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
public class Map extends MapActivity {
MapView map;
long start;
long stop;
private final int mRadius = 5;
public void onCreate(Bundle SavedInstanceState) {
super.onCreate(SavedInstanceState);
setContentView(R.layout.mapview);
map = (MapView)findViewById(R.id.mvMapview);
map.setBuiltInZoomControls(true);
map.displayZoomControls(true);
map.setSatellite(true);
map.setStreetView(true);
Touchy t = new Touchy();
List<Overlay> overlaylist = map.getOverlays();
overlaylist.add(t);
}
public void draw(Canvas canvas, MapView mapView, boolean shadow){
Projection projection = mapView.getProjection();
if (shadow == false) {
Bundle extras = getIntent().getExtras();{
if(extras!=null){
String longitude =extras.getString("Longitude");
String latitude =extras.getString("Latitude");
}
}
double latitude;
double longitude;
GeoPoint geoPoint;
geoPoint = new GeoPoint((int) ( latitude *1E6), (int) (longitude * 1E6));
Point point = new Point();
projection.toPixels(geoPoint, point);
RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius);
Paint paint = new Paint();
paint.setARGB(250, 255, 255, 255);
paint.setAntiAlias(true);
paint.setFakeBoldText(true);
Paint backPaint = new Paint();
backPaint.setARGB(175, 50, 50, 50);
backPaint.setAntiAlias(true);
RectF backRect = new RectF(point.x + 2 + mRadius, point.y - 3*mRadius, point.x + 65, point.y + mRadius);
canvas.drawOval(oval, paint);
canvas.drawRoundRect(backRect, 5, 5, backPaint);
canvas.drawText("This is it", point.x + 2*mRadius, point.y,paint);
}
super.draw(canvas.MapView.shadow);
}
我不知道为什么会弹出这个错误。我已经尝试修复它,但地图视图错误始终存在