I need to get the Users Location for my app so that i can display the directions on Google Maps based on two Lat and Long.
If the Users GPS is switched off it should ask the user if he wants to switch on the GPS and should be able to take him the Settings to switching it on.
i am trying the following but it takes me directly to the settings i wonder how to let the user ask if he wants to be taken away.
Is there any Library that does this efficiently i would prefer using it to get the Lat and Long of the user.
You will need to do several things.
Firstly, to incorporate Google Maps, your complete reference is available here.
In simple steps:
1 Follow the steps here: this will help add a simple google maps to your screen.
2 To be able to get your own location you will need to use the LocationListener and LocationManager in android. To do this, first implement the LocationListener in your activity.
public class LocationActivity extends Activity implements LocationListener3 Then you need to instantiate a few settings in your onCreate() method
4 You need to be able to request for regular location updates. Include this in your onResume() method.
5 If the app falls into the pause cycle, these updates shouldn’t need to come.
6 Your location listener implementation from step 2 requires that you have an onLocationChanged listener, implement it:
7 Add these two methods to be notified of the provider of your location setting – the GPS or the Network.
8 Now we need to link this up to your google maps. I will show you one example of using the google maps API to be able to generate a market to show your current location. The other usages can be inferred from the API.
First create private fields in your code:
9 Add these in your onCreate method – this instantiates your default marker position as 0,0 latitude and longitude.
10 In your onLocationChanged method, we need to refresh this marker as location changes. So add:
This will be a simple way of updating the marker with your position, and should be a good intro to your Google Maps and location API in android.
To detect if GPS is on or not you can use the answer provided by @Dror 🙂 Hope it helps!