Amit
Amit

Reputation: 21

Android Network Location Provider Issue

Does android network location provider work without internet or wifi?. i am facing inconsistencies in this behavior as sometimes my onlocationchanged() method is getting called even when there is no internet/wifi.

Sometimes i am not getting a location fix if internet/wifi is off with the following message " Too many no location ap-s.Not compute a location" for wifilocator and for celllocator-Primary cell miss in cache.

Please let me know how do i fix this?

I am using API 7.Testing this app on android 2.3.6 Samsung Galaxy Y.

Upvotes: 2

Views: 1262

Answers (1)

Manish Dubey
Manish Dubey

Reputation: 4306

Put your onLocationChanged() method within this :

    public boolean haveNetworkConnection()
     {
       ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
       NetworkInfo netInfo = cm.getActiveNetworkInfo();
       if (netInfo == null)
          return false;
      else
          {
          if(netInfo.isConnected())
              return true;
          else
              return false;
          }
    }

Hope ! This will help. Try this.

When I reviewed your question again. I found this :

Yes, you need to be connected to the Internet in order to get correct network location fixes. At least most of the time. The phone collects the following data (it does not need a connection to the Internet to do this):

  • nearby wifi information by scanning for wifi access points.

  • nearby mobile cell information is available from the phone's cellular radio.

The phone then sends this data to a server. The server uses this data to look in its database to determine the phone's most likely position. The server sends the location information back to the phone. This is all done using data connection via Internet (either mobile Internet or wifi). Some implementations additionally download a small amount of the server's database to the phone (describing a small area around the phone's current position) so that the phone doesn't have to query the Internet all the time. However, once the phone has moved outside of this small area it will need to access the Internet to get correct locations again.

So, basically, without Internet connectivity you can't (reliably) use network location.

Upvotes: 1

Related Questions