Android GPS cloud of confusion!

Posted by Anthony Forloney on Stack Overflow See other posts from Stack Overflow or by Anthony Forloney
Published on 2009-10-13T01:36:53Z Indexed on 2010/03/14 17:55 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

I am trying to design my first Android application with the use of GPS. As of right now, I have a drawable button that when clicked, alerts a Toast message of the longitude and latitude. I have tried to use the telnet localhost 5554 and then geo fix #number #number to feed in values but no results display just 0 0. I have also tried DDMS way of sending GPS coordinates and I get the same thing.

My question is what exactly is the code equivalent to the geo fix and the DDMS way of sending coordinates. I have used Location, LocationManger and LocationListener but I am not sure which is the right choice.

Could anyone explain to me what the code-equivalent just so I can get a better understanding of how to fix my application not working. Code is given, just in case if the error exists with the code

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button button = (Button) findViewById(R.id.track);
    button.setOnClickListener(this);
    LocationManager location =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    Location loc = location.getLastKnownLocation(location.GPS_PROVIDER);
    updateWithNewLocation(loc);

  }

 private final LocationListener locationListener = new LocationListener() {
   public void onLocationChanged(Location location) {
     updateWithNewLocation(location);
   }

  private void updateWithNewLocation(Location l) {
  longitude = l.getLongitude();
  latitude = l.getLatitude();
  provider = l.getProvider();     
  }

    public void onClick(View v) { 
     Toast.makeText(this, "Your location is " + 
      longitude + " and " + latitude + " provided by: " + 
      provider, Toast.LENGTH_SHORT).show();          
   }     
}

© Stack Overflow or respective owner

Related posts about android

Related posts about gps