GPS Code errors

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

GPS Code errors

Postby ronheberlein » Thu Jan 28, 2010 7:24 am

I am working on creating my first android code, and I am having some problems.
I was using a dexv article for help on the code: http://www.devx.com/wireless/Article/43005/1954

I am getting the following errors when I write the code in eclipse:
The type new LocationListener(){} must implement the inherited abstract methodLocationListener.onLocationChanged (Location)
and
- Location cannot be resolved to a type

Here is the code:
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.location.LocationListener;
import android.location.LocationManager;


public class flightnav extends Activity {

/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState) {
LocationManager locMan;
locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, gpsListener);
}

LocationListener gpsListener = new LocationListener(){
Location curLocation;
boolean locationChanged = false;
public void onLocationChanged(Location location)
{
if(curLocation == null)
{
curLocation = location;
locationChanged = true;
}

if(curLocation.getLatitude() == location.getLatitude() &&
curLocation.getLongitude() == location.getLongitude())
locationChanged = false;
else
locationChanged = true;

curLocation = location;
}
public void onProviderDisabled(String provider){}
public void onProviderEnabled(String provider){}
public void onStatusChanged(String provider, int status, Bundle extras){}

};
}

Any help would be greatly appreciated.
ronheberlein
Freshman
Freshman
 
Posts: 5
Joined: Thu Jan 28, 2010 7:18 am

Top

Re: GPS Code errors

Postby naveenballa » Thu Jan 28, 2010 10:55 am

ronheberlein wrote:I am working on creating my first android code, and I am having some problems.
I was using a dexv article for help on the code: http://www.devx.com/wireless/Article/43005/1954

I am getting the following errors when I write the code in eclipse:
The type new LocationListener(){} must implement the inherited abstract methodLocationListener.onLocationChanged (Location)
and
- Location cannot be resolved to a type

Here is the code:
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.location.LocationListener;
import android.location.LocationManager;


public class flightnav extends Activity {

/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState) {
LocationManager locMan;
locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, gpsListener);
}

LocationListener gpsListener = new LocationListener(){
Location curLocation;
boolean locationChanged = false;
public void onLocationChanged(Location location)
{
if(curLocation == null)
{
curLocation = location;
locationChanged = true;
}

if(curLocation.getLatitude() == location.getLatitude() &&
curLocation.getLongitude() == location.getLongitude())
locationChanged = false;
else
locationChanged = true;

curLocation = location;
}
public void onProviderDisabled(String provider){}
public void onProviderEnabled(String provider){}
public void onStatusChanged(String provider, int status, Bundle extras){}

};
}

Any help would be greatly appreciated.



Try now with this code
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2. import android.content.Context;
  3. import android.os.Bundle;
  4. import android.location.Location;
  5. import android.location.LocationListener;
  6. import android.location.LocationManager;
  7.  
  8.  
  9. public class Test extends Activity {
  10.  
  11. /** Called when the activity is first created. */
  12. @Override
  13.  
  14. public void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         LocationManager locMan;
  17.         locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  18.         locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, gpsListener);
  19.         }
  20.        
  21.         LocationListener gpsListener = new LocationListener(){
  22.                                 Location curLocation;
  23.                                 boolean locationChanged = false;
  24.                                 @Override
  25.                                 public void onLocationChanged(Location location)
  26.                                 { System.out.println("location changed");
  27.                                         if(curLocation == null)
  28.                                         {
  29.                                                 curLocation = location;
  30.                                                 this.locationChanged = true;
  31.                                         }
  32.                                        
  33.                                         if(curLocation.getLatitude() == location.getLatitude() &&
  34.                                                         curLocation.getLongitude() == location.getLongitude())
  35.                                                 locationChanged = false;
  36.                                         else
  37.                                                 locationChanged = true;
  38.                                        
  39.                                         curLocation = location;
  40.                                 }
  41.                                 public void onProviderDisabled(String provider){}
  42.                                 public void onProviderEnabled(String provider){}
  43.                                 public void onStatusChanged(String provider, int status, Bundle extras){}
  44.                                
  45.                        
  46.                                 };
  47. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
naveenballa
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Nov 16, 2009 12:53 pm

Postby ronheberlein » Thu Jan 28, 2010 3:58 pm

Thanks for the help, that resolved the errors that I had.
I now get the following warning message "The field new LocationListener(){}.locationChanged is never read locally" at this line of code:
boolean locationChanged = false;

One of the suggestions by eclipse is to add:
@SuppressWarnings("unused")

Am I missing something in the code, or is it just a warning message that can be ignored?
ronheberlein
Freshman
Freshman
 
Posts: 5
Joined: Thu Jan 28, 2010 7:18 am

Postby naveenballa » Fri Jan 29, 2010 5:24 am

its not at all a problem
warning is because u are not using the variable(Reading the variable)..
naveenballa
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Nov 16, 2009 12:53 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 7 guests