views:

169

answers:

2

Hi all..

i am working on an application that needs to find GPS location of the user. While testing my code on Droid i am unable to find the GPS location. While googling i found this link to an issue raised with Google.

But apps like Yelp can find the GPS location on droid. Is there a workaroud to find the user location on a device? Here's the code I am using

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationProvider;
import android.os.Bundle;

public class MyLocationListener implements LocationListener {

private static double latitude;
private static double longitude;

public static boolean gpsAvailable = false;

@Override
public void onLocationChanged(Location arg0) {
    latitude = arg0.getLatitude();
    longitude = arg0.getLongitude();
    // Log.d("MyLocationListener", "onLocationChanged");
}

@Override
public void onProviderDisabled(String provider) {

    // Log.d("MyLocationListener", "onProviderDisabled");
}

@Override
public void onProviderEnabled(String provider) {
    // Log.d("MyLocationListener", "onProviderEnabled");
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // Log.d("MyLocationListener", "onStatusChanged called");
    if (provider.equals("gps") && status != LocationProvider.AVAILABLE) {
        gpsAvailable = false;
        // Log.d("MyLocationListener", "status NOTAVAILABLE");
    } else {
        gpsAvailable = true;
        // Log.d("MyLocationListener", "status AVAILABLE");
    }
}

public static double getLatitude() {
    return latitude;
}

public static double getLongitude() {
    return longitude;
}

}

thanks..

A: 

Are you requesting location updates elsewhere in your code?

LocationManager manager = new LocationManager();
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 500, new MyLocationListener());

I am writing an app with very similar functionality and I've been testing on a Droid. GPS support works well on the Droid so I don't think your problem is device specific.

jeremynealbrown
No, i am not requesting location updates elsewhere. I am just calling it once at the start of the application.
mudit
So at some point in your code you are adding listeners? I don't see that in your sample.
jeremynealbrown
Have you added these two lines to the manifest file?<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
jeremynealbrown
Yes.. I have added all these permissions.. plus i am also able able to get locations on G1 and HTC hero..but unable to find it on droid...
mudit
A: 

Never had a problem using GPS on Droid. You need to manually turn on GPS in the parameters of your phone to use it, and add adequate permissions to the manifest file. Is there anything in the logcat that could explain what happens?

Stéphane
i have added permissions in manifest..how i do i turn on GPS manually??
mudit
Don't have the phone right here but it's something like settings>location>use GPS satellites.Check also this other stackoverflow thread : http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is-enabled
Stéphane