How to get latitude and longitude offline in android ?

一世执手 提交于 2019-12-20 03:16:09

问题


I want to get current location (latitude & longitude) , when WiFi & Gps is off .It is possible to get latitude and longitude from mobile sim network. I searched more on google but i did not get satisfies answers.


回答1:


Try This

 LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if(location==null){
        location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }



回答2:


From my yesterday's experience on this question, I finally found out that it is impossible to fetch latitude longitude's value without Internet connection in device. ( Gosh I spent 3 hours to find why my running code working properly. ) Even to get the value from getLastKnowLocation() you must require Internet connection.




回答3:


Pretty sure this is impossible. While you can store cell tower ID's to know when you're close to an area you've been in before, you can't actually use these values to get latitude and longitude numbers (Well, unless you stored some lat and long values and paired them with that cell tower). You can however call getLastKnownLocation() to... get the last known location from the GPS or Wifi.

Edit

Apparently google has built a database of lat/long with cellID's already. It is not part of the standard Android API, and requires a network connection to hit. Pretty cool though. You can find more at this (really slow) website



来源:https://stackoverflow.com/questions/22085589/how-to-get-latitude-and-longitude-offline-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!