1

我检查我的 logcat 文件错误是位置管理为空

公共类 MapsActivity 扩展 MapActivity { MapView mapView; 地图控制器 mc; 地理点 p; 双 latPoint, lngPoint; 位置管理器我的管理器;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapView);
    LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
    View zoomView = mapView.getZoomControls();

    zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mapView.displayZoomControls(true);

    mc = mapView.getController();
     LocationManager myManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new myLocationListener());

    p = new GeoPoint((int) (latPoint * 1E6), (int) (lngPoint * 1E6));

    mc.animateTo(p);
    mc.setZoom(10);

    //---Add a location marker---

// MapOverlay mapOverlay = new MapOverlay(); // 列表 listOfOverlays = mapView.getOverlays(); // listOfOverlays.clear(); // listOfOverlays.add(mapOverlay);

    mapView.invalidate();

}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

class myLocationListener implements LocationListener {

    public void ListLocationUpdater() {
    }

    @Override
    public void onLocationChanged(Location loc) {
        if (myManager != null) {
            // List list = myManager.getAllProviders();
            String param = (String) myManager.getProviders(true).get(0);
            loc = myManager.getLastKnownLocation(param);
            if (loc != null) {
                latPoint = loc.getLatitude();
                lngPoint = loc.getLongitude();
                Log.e("RootDrawApplication",String.valueOf(latPoint)+"  , "+String.valueOf(lngPoint));

            } else
                Log.e("GoogleMaps ", "Error: Location  is null");
        } else
            Log.e("GoogleMaps ", "Error: Location Manager is null");
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

}

}

4

1 回答 1

0

您应该设置一个 LocationListener(此处)。在 LocationListener 的 onLocationChanged 方法中,只需让您的地图动画到更新的位置。

于 2011-04-08T14:32:45.927 回答