how can i get location without internet in android i wnat to know location only using GPs
-
i want toget location using GPS only. i dnt want to use internet and GPRS in this application. so tell me how can i get location using only GPS provider. my code is belo. tell me where m wrong in this. code. package com.getlocation; import android.app.Activity; import android.content.Context; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.widget.Toast; public class UseGps extends Activity { /** Called when the activity is first created. */ private String provider; LocationManager locationManager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /* * Use the LocationManager class to * obtain GPS locations */ locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener mlocListener = new MyLocationListener(); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setAccuracy(Criteria.ACCURACY_FINE); provider = locationManager.getBestProvider(criteria, true); locationManager.requestLocationUpdates(provider, 61000, 250, mlocListener); } /* Class My Location Listener */ public class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { loc.getLatitude(); loc.getLongitude(); String Text = "My current location is: " + "Latitude = " + loc.getLatitude() + "Longitude = " + loc.getLongitude(); Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT) .show(); Log.d("TAG", "Starting.."); } @Override public void onProviderDisabled(String provider) { Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT).show(); } @Override public void onProviderEnabled(String provider) { Toast.makeText(getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }/* End of Class MyLocationListener */ }/* End of UseGps Activity */
-
Answer:
Use this for only GPS Provider, it does not need GPRS. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener); <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> You need to put the permission in manifest file.
Sam_k at Stack Overflow Visit the source
Other answers
You don't need an internet connection to run GPS system in your mobile. GPS time synchronization does not require an Internet connection. But if you want to show the current location on google map, you may require internet connection. Coming to you code everything looks fine for me. Try this code in your activity. LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener mlocListener = new YourLocationListener(getApplicationContext(), mobileNo, deviceId); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,mlocListener); and include this in androidmanifest.xml <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_GPS" /> <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
Krishna
Related Q & A:
- How can I trick SSH to connect using different configurations based on current location?Best solution by Server Fault
- How can I get my sss contribution through internet?Best solution by Yahoo! Answers
- How can i get my Tax Identification through internet?Best solution by Yahoo! Answers
- How Can I Connect To The Internet On My Psp Using A USB Cable?Best solution by askdavetaylor.com
- How can I get into my Yahoo mail that I haven't used for a while?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.