本文介绍了在我离线时获取我的gps位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些关于获得我的GPS位置的研究。我使用谷歌地图API v2,以便获得我当前的位置,我用这个



$ location $ locationManager =(LocationManager)getSystemService定位服务);
列表< String> providers = locationManager.getAllProviders();
标准标准=新标准();
bestProvider = locationManager.getBestProvider(criteria,false);

位置位置= locationManager.getLastKnownLocation(bestProvider);

所以根据我的理解,在 locationManager getLastKnowLocation()返回该列表中的最后一个条目。此外,如果此列表不为空,我可以在我的应用程序处于脱机状态时获取最后一个条目。



但没有位置返回给我。



所以我的第一个问题是:列表中的条目可用于我的应用程序多长时间如果没有互联网连接一段时间,检索他们。



另外,我将检索的位置将是我在线时修复的最后一个正确的位置?所以即使我可以检索它,它也不会准确,那么当我的手机处于离线状态时,是否有另一种方法可以获取当前的gps位置? (即通过gps或gsm网络)
感谢您的时间。

解决方案

首先,您没有连接到互联网,通过GPS获取位置更新。如果您的设备支持GPS,那么如果您在户外并且可以通过GPS获取位置更新,它将连接到GPS卫星。 了解如何使用位置提供商。




同样被告知,如果提供者未被开启,getLastKnownLocation()将总是返回null。如果提供者当前被禁用,则返回null。



I've doing some research about getting my gps position. I'm using google maps API v2 so in order to get my current position I used this

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    List<String> providers = locationManager.getAllProviders();
    Criteria criteria = new Criteria();
    bestProvider = locationManager.getBestProvider(criteria, false);

    Location location = locationManager.getLastKnownLocation(bestProvider);

so from my understanding there is a list in the locationManager and getLastKnowLocation() returns the last entry from that list. Also if this list is not empty I can get the last entry while my application is offline.

I happened to have my wifi off for the weekend and checked to see if it works but no location was returned to me.

So my first question is: how long are the entries in the list available for my application to retrieve them provided there is no internet connection for a while.

Also the location that I will be retrieving will be the last which was fixed while I was online correct? so even If I can retrieve it, it won't be accurate so is there another way to get my current gps location while my cell is offline? (ie via gps or gsm network)Thank you for your time.

解决方案

Firstly, you don't have to be connected to internet to get location updates through GPS. If your device supports GPS, it will get connected to the GPS satellites if your outdoors and you can get the location updates through GPS. Read this to know how to use location providers.

Also be informed that if the provider is not turned on, getLastKnownLocation() will always return null. Quoting from android documentaion,

这篇关于在我离线时获取我的gps位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 03:23