Простой способ добавить геолокацию в свой проект для Android
Долго я прочёсывал интернет в поисках простого решения, как мне в проект добавить 1 только класс и больше не беспокоиться о проблемах геолокации.
Критерии были такие:
1) решить всё в 1 классе, как можно меньше используя внешний код.
2) у пользователя должна быть всегда под рукой 1 static переменная в которой указанно его местоположение и больше ни о чём он знать не должен.
Большинство постов не отвечало на поставленный вопрос: конечно сначала нужно обратиться к сервису, потом нужно установить listner, потом вы можете посмотреть на трёхстраничный краткий пример как это делать.
В итоге я написал свой класс, с которым и хочу вас познакомить: он прост в использовании и с ним сможет справиться любой: просто добавьте его в проект и будет вам счастье.
Итак, что же здесь есть?
Класс разделен на 3 части:
1) imHere — переменная типа Location, в которой будет всегда доступна самая последняя информация о местоположении пользователя.
2) функция SetUpLocationListener — в любом случае нам нужна будет начальная установка для того, чтобы система начала сама без нашего участия выполнять обновление переменной imHere.
3) все остальные обязательные части LocationListener, которые можно переделать по собственному желанию.
Итак, как это работает?
1) создаем класс MyLocationListener
2) копируем в него код написанный выше
3) в основной функции (например MainActivity) ближе к началу запускаем:
или для любителей потоков
4) теперь у нас всегда и в любой части нашего проекта есть переменная MyLocationListener.imHere типа Location, в которой хранится самое последнее местоположение пользователя и множество дополнительной информации, как например скорость или точность определения местоположения.
И в заключение: это принципиальный код и тут есть что улучшать. Например нужно учитывать, что первое время локация может быть не определена и imHere будет null, но это всё не скоро: сейчас у нас есть класс, который позволяет нам без лишних усилий и с минимумом знаний добавить геолокацию в свой проект.
(!) Не забудьте: в зависимости от выбранного провайдера нужно добавить в манифест соответствующее разрешение. Например используемый выше GPS_PROVIDER требует добавления следующей строчки в манифест:
Источник
Phone · Location Tracker 4+
Telefirst Telecom Services LLP
Для iPhone
-
- Бесплатно
- Включает встроенные покупки
Снимки экрана (iPhone)
Описание
Find My Friends Phone location is an easy-to-use application to track and locate and track friends, family, even a lost iPhone.
Find My Friends Phone location is an app that provides a real time locator service allowing family members and close friends to privately share their location information and communicate with each other.
Find My Friends Phone location is the answer to how to find my friends and find my phone.
This family and friends locator app helps you to get notified when your family or your friend arrive in their destination and check in.
The location sharing feature keeps the one you love safe all time.
Our app features are
—Get real-time location of your family and your friends as a friend finder and family locator
—Create unique circle with your friends and family as a family finder
—Create different circles for your children, babysitters, colleagues and more
—Invite your friends and family to your circle to view their exact location easily
—Join in circles you want by entering the shared invitation code in this family locator
—See current battery level and send alerts when someone device’s battery level is low.
As a family & friends location app, Find My Friends Phone location is able to find your family and friends and report where they are.
Each member would appear on a map with unique icon after registration so that you can always know the real-time of your family and find friends.
Protect them all the time with this location sharing app!
Find My Friends Phone location can also help you to check whether you children have arrived in school or home safely!
Subscription Information:
• 1 week subscription which comes with a 3-day free trial for $3.99 USD.
• 1 Month subscription which comes with a 3-day free trial for $14.99 USD.
• 1 Year subscription which comes with a 3-day free trial for $49.99 USD.
• Payment will be charged to iTunes Account at confirmation of purchase
• Subscription automatically renews unless auto-renew is turned off at least 24-hours before the end of the current period
• Account will be charged for renewal within 24-hours prior to the end of the current period, and identify the cost of the renewal
• Subscriptions may be managed by the user and auto-renewal may be turned off by going to the user’s Account Settings after purchase
• Any unused portion of a free trial period, if offered, will be forfeited when the user purchases a subscription to that publication, where applicable
Источник
Phone · Location Tracker 4+
Telefirst Telecom Services LLP
Для iPhone
-
- Бесплатно
- Включает встроенные покупки
Снимки экрана (iPhone)
Описание
Find My Friends Phone location is an easy-to-use application to track and locate and track friends, family, even a lost iPhone.
Find My Friends Phone location is an app that provides a real time locator service allowing family members and close friends to privately share their location information and communicate with each other.
Find My Friends Phone location is the answer to how to find my friends and find my phone.
This family and friends locator app helps you to get notified when your family or your friend arrive in their destination and check in.
The location sharing feature keeps the one you love safe all time.
Our app features are
—Get real-time location of your family and your friends as a friend finder and family locator
—Create unique circle with your friends and family as a family finder
—Create different circles for your children, babysitters, colleagues and more
—Invite your friends and family to your circle to view their exact location easily
—Join in circles you want by entering the shared invitation code in this family locator
—See current battery level and send alerts when someone device’s battery level is low.
As a family & friends location app, Find My Friends Phone location is able to find your family and friends and report where they are.
Each member would appear on a map with unique icon after registration so that you can always know the real-time of your family and find friends.
Protect them all the time with this location sharing app!
Find My Friends Phone location can also help you to check whether you children have arrived in school or home safely!
Subscription Information:
• 1 week subscription which comes with a 3-day free trial for $3.99 USD.
• 1 Month subscription which comes with a 3-day free trial for $14.99 USD.
• 1 Year subscription which comes with a 3-day free trial for $49.99 USD.
• Payment will be charged to iTunes Account at confirmation of purchase
• Subscription automatically renews unless auto-renew is turned off at least 24-hours before the end of the current period
• Account will be charged for renewal within 24-hours prior to the end of the current period, and identify the cost of the renewal
• Subscriptions may be managed by the user and auto-renewal may be turned off by going to the user’s Account Settings after purchase
• Any unused portion of a free trial period, if offered, will be forfeited when the user purchases a subscription to that publication, where applicable
Источник