Finding Yourself

 

The obvious thing to do with a location service is to figure out where you are right now.

To do that, you need to get a – call from your activity or service and cast it to be a .

The next step to find out where you are is to get the name of the you want to use. Here, you have two main options:

• Ask the user to pick a provider.

• Find the best‑match provider based on a set of criteria.

If you want the user to pick a provider, calling on the will give you a of providers, which you can then present to the user for selection.

Or, you can create and populate a object, stating the particulars of what you want out of a , such as the following:

• to indicate if you need the current altitude or not

• to set a minimum level of accuracy, in meters, for the position

• to control if the provider must be free or not (i.e., if it can incur a cost on behalf of the device user)

Given a filled‑in object, call on your , and Android will sift through the criteria and give you the best answer. Note that not all of your criteria may be met – all but the monetary‑cost criterion might be relaxed if nothing matches.

You are also welcome to hard‑wire in a name (e.g., ), perhaps just for testing purposes.

Once you know the name of the , you can call to find out where you were recently. Note, however, that “recently” might be fairly out‑of‑date (e.g., if the phone was turned off) or even null if there has been no location recorded for that provider yet. On the other hand, incurs no monetary or power cost, since the provider does not need to be activated to get the value.

These methods return a object, which can give you the latitude and longitude of the device in degrees as a Java . If the particular location provider offers other data, you can get at that as well:

• For altitude, will tell you if there is an altitude value, and will return the altitude in meters.

• For bearing (i.e., compass‑style direction), will tell you if there is a bearing available, and will return it as degrees east of true north.

• For speed, will tell you if the speed is known, and will return the speed in meters per second.

A more likely approach to getting the from a , though, is to register for updates, as described in the next section.

 








Дата добавления: 2015-05-16; просмотров: 787;


Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми.
helpiks.org - Хелпикс.Орг - 2014-2024 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.003 сек.