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()));
}

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 回答