0

「青い点」の位置座標を取得し、それを最初のマップビュー読み込みの中心として設定しようとしています。しかし、ヌルポインタ例外が発生しています。

ここで何が欠けていますか?

public class GetLocationActivity extends MapActivity implements OnClickListener {
private MapView location;
private LocationMarker locationMarker;
private MyLocationOverlay locationOverlay;
private GeoPoint destination;
private GeoPoint source;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.location);

    location = (MapView) this.findViewById(R.id.location);
    location.setBuiltInZoomControls(true);
    location.setClickable(true);
    location.setLongClickable(true);
    location.getController().setZoom(12);
    locationMarker = new LocationMarker(this, location, marker,
            (ImageView) findViewById(R.id.drag));
    location.getOverlays().add(locationMarker);
    locationOverlay = new MyLocationOverlay(this, location);
    location.getOverlays().add(locationOverlay);
    source = locationOverlay.getMyLocation();
    location.getController().setCenter(
            new GeoPoint(source.getLatitudeE6(), source.getLongitudeE6()));
}

で nullPointer を取得しsource.getLatitudeE6()ます。

4

1 に答える 1

0

ここで私の基本を忘れて:)。LocationManagerを使用して現在地を取得する必要があります。

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
            (LocationListener) this);
于 2013-02-06T12:08:58.690 に答える