1. Are you ready for the Galaxy S20? Here is everything we know so far!

Unable to implement LocationListener

Discussion in 'Android Development' started by Bretterson, Dec 21, 2009.

  1. Bretterson

    Bretterson Lurker
    Thread Starter

    I'm trying to make an app that just gets gps coordinates and displays them. I found that you need to do LocationManager.requestLocationUpdates() in order to get it to work, but this requires you to have an implemented LocationListener as a parameter. I've found tons of sites showing how to do this, and they're all doing it basically the same way, but for some strange reason it won't work for me. Here's my implementation:

    Code (Text):
    1. private class MyLocationListener implements LocationListener
    2.     {
    3.         @Override
    4.         public void onLocationChanged(Location loc) {
    5.             if (loc != null) {
    6.                 Toast.makeText(getBaseContext(),
    7.                     "Location changed : Lat: " + loc.getLatitude() +
    8.                     " Lng: " + loc.getLongitude(),
    9.                     Toast.LENGTH_SHORT).show();
    10.             }
    11.         }
    13.         @Override
    14.         public void onProviderDisabled(String provider) {
    15.             // TODO Auto-generated method stub
    16.         }
    18.         @Override
    19.         public void onProviderEnabled(String provider) {
    20.             // TODO Auto-generated method stub
    21.         }
    23.         @Override
    24.         public void onStatusChanged(String provider, int status,
    25.             Bundle extras) {
    26.             // TODO Auto-generated method stub
    27.         }
    28.     }
    Now when I try to run it it gives errors on each of the overridden methods. They're all basically the same. Here's the one for OnLocationChanged:
    The method onLocationChanged(Location) of type HelloViaSocket.MyLocationListener must override a superclass method

    Everything I've seen says that LocationListener should have OnLocationChanged and all the other methods I'm trying to override, so why is it doing this?

    I tried deleting my Google API's from the SDK, and then re-downloading and installing them, but I'm getting the same problem.

    Does anyone have any idea what I'm doing wrong?


    1. Download the Forums for Android™ app!


  2. KeithG

    KeithG Well-Known Member

    remove the @override annotations.
  3. lugosi

    lugosi Lurker

    I had the same problem on Eclipse Helios, but i had az another project, what works fine.
    The problem was that, the project folder in the .settings had source set to 1.5.
    After remove the .settings folder, it compiled without any warning.

Share This Page