0

I'm new to this and it has taken lots of time trying to figure this out. I have this code below as it seems not to be working and sometimes crashes. I know it might be a little thing holding it but would need help to get it fixed and running.

Can someone help in correcting please as i want to learn as well.

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;
        }
Unheilig
  • 16,196
  • 193
  • 68
  • 98
obinna
  • 1
  • 1
    Please, provide more information about crashes -> where, what is in the log, etc. – ivan.mylyanyk Mar 28 '15 at 13:22
  • If you are using Android Studio and willing to add a small library, then I can recommend https://github.com/mcharmas/Android-ReactiveLocation It is by far the simplest yet most flexible way of getting fused locations that I have found. It can furthermore handle geofencing and activity detection in case that is of interest as well. – cYrixmorten Mar 28 '15 at 13:36
  • Thank you cY but no i am using eclipse – obinna Mar 29 '15 at 15:41

1 Answers1

0

Can't guarantee it's the only issue, but for one, you pass a null LocationListener to your LocationManager.

You will have to instantiate that listener. Otherwise it won't listen for anything. It will look something along the lines of this:

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
        }
    };
Treeline
  • 475
  • 1
  • 8
  • 23