Zakharov Roman
Zakharov Roman

Reputation: 779

How to get user's location?

I want to get user's location in my app. So, I read documentations and know how to get it work. But, if user haven't set "Alloy apps to use internet/GPS to get location" in preferences, my app crashes.

The only way I found is to show dialog that location settings are not enabled and to go programmaticaly to location preferences.

But is there another way to solve this? I saw many apps (like yandex.maps) that do not request this settings being enabled.

Upvotes: 1

Views: 636

Answers (2)

Rushabh Patel
Rushabh Patel

Reputation: 3080

Refer this two links below and you might get your answer easily.

How do I get the current GPS location programmatically in Android?

android - how to get current location latitude and longitude

Hope it will help you.

Upvotes: 1

thepoosh
thepoosh

Reputation: 12587

well, your app should not install if the user doesn't agree to the terms of use, and allow the permissions requested.

still you should check to see that there's a way to look the information up when you want it.

in your code, before the actual test for user's location, you should probably call a function that checks for all the location manager listings, and return false if there's no way to determine this.

if the function returns false, you should prompt the user and do nothing. else, you should do what it is you're trying to do.

try reading vogella's tutorial about using location manager

Upvotes: 2

Related Questions