Link to home
Start Free TrialLog in
Avatar of shahjagat
shahjagatFlag for United States of America

asked on

Android GPS Location Without Internet

I want to develop an Application which will store the Longitude and Latitude of
an Android device into device internal database, Using Device's GPS Chip and Not using Internet at all.

Can some one provide me the source code for the same.
Avatar of Argenti
Argenti
Flag of France image

Hello shahjagat,

While I won't provide you with a fully functional example application, I can show you some useful links that you could use in order to achieve your goal:

- Here is how to create a database for your android application
- Here is how to get your GPS coordinates

Now you should be able to do your application just by combining those two pieces of information (creating your own DB application + getting your GPS coordinates + saving your coordinates into your database). As you can see, it doesn't implies using internet connection at all.

Good luck!
Avatar of Chris Harte
In the tutorial on gps replace the line

provider = locationManager.getBestProvider(criteria, false);

with

provider = LocationManager.GPS_PROVIDER;

This will force the activity to use gps rather than network. In my experience android always defaults to 'network' even when there is no network connectivity.
Avatar of shahjagat

ASKER

Thanks Argenti,

But...

I am new android developer

I am using below code, but it does not return latitude and longitude when internet is OFF,
I also want to calculate speed, distance covered and odometer reading ,
My device will be inside the bus and in the region where there is no internet.

Any help will be appreciated,  

My code
MIN_TIME_BW_UPDATES=1 minute;
MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null)
      {
             location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (location != null) {
                  latitude = location.getLatitude();
                  longitude = location.getLongitude();
            }
      }
ASKER CERTIFIED SOLUTION
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for all answers