我是新手,并且花了很多时间试图解决这个问题。我在下面有这个代码,因为它似乎没有工作,有时崩溃。我知道它可能是一个小东西,但需要帮助才能使其得到修复和运行。
有人可以帮忙纠正,因为我也想学习。
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 android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends MapActivity {
protected static final GeoPoint Geopoint = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView view = (MapView) findViewById(R.id.mapview);
view.setBuiltInZoomControls(true);
final MapController control = view.getController();
LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener listener = null;
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
//control.setCenter(new GeoPoint((int)((LocationManager) manager).getLatitude(), (int)((LocationManager) manager).getLongitude()));
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
答案 0 :(得分:0)
不能保证它是唯一的问题,但对于一个问题,您将空LocationListener
传递给LocationManager
。
您必须实例化该侦听器。否则它不会听任何东西。它将看起来像这样:
LocationListener listener = new LocationListener(){
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
// This is where you can get your newest location
}
};