How can I get location without internet in android, using only GPS

前端 未结 2 812
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 00:52

I want to get location using GPS only. I don\'t want to use internet and GPRS in this application. My code is below; tell me where I\'m wrong in this.

code:

相关标签:
2条回答
  • 2020-12-29 01:02

    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 android:name="android.permission.ACCESS_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
    
    0 讨论(0)
  • 2020-12-29 01:18

    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.

    0 讨论(0)
提交回复
热议问题