Gps not working sometimes in some of the applications for android

I was working with Gps for fetching current lat and long in my application, it was working nicely with android 2.3.3 and even in some of my higher versions android devices but sometimes in some of the devices its just behaving opposite although gps is on its showing error message that GPS is not connected please turn on the gps this is the message i used when gps is not detecting. can anyone please help me on this ? Below is my code for detecting and getting GPS

    private void bindgeocodelocation() {
    latlong = new ArrayList<String>();

    latlong = GeneralFunction.getcurrentlocation(Search.this);
    if (latlong == null) {
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Location loc = lm
                .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 100, 1,
                locationListener);
        if (loc != null) {
            latlong = new ArrayList<String>();
            latlong.add("" + loc.getLatitude());
            latlong.add("" + loc.getLongitude());
        } else if (lm != null) {
            lm.removeUpdates(locationListener);
        }
    }

}

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

        try {
            latlong = new ArrayList<String>();
            latlong.add(location.getLatitude() + "");
            latlong.add(location.getLongitude() + "");
            // webviewdata();
        } catch (Exception e) {
            Log.e("Error", e.getMessage().toString());
        }

    }

    @Override
    public void onProviderDisabled(String provider) {
        Log.i("Info", "Provider disable");

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }
};

Answers


Then if you make that device outdoor for some time, it may work. In some low end devices, gps may not work properly at all. Else try upgrading GooglePlayServices too. Also I suggest you to use multiple providers instead of only one NETWORK_PROVIDER


Sometimes the particular device's google play services are outdated I've faced the similar problem. Your code seems fine The only issue can be the google playe services are outdated.


Need Your Help

Export Data From Web To Excel With More Performance

.net performance excel export

We are using a different framework, and I cannot use .NET GridView. We have a different Collection type and specialized grid.(Not inherit from .NET controls) I need to export data from web to MS-Ex...

An unknown Java syntax

java

Let's see the following code snippet in Java.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.