THIS CONTENT DOWNLOAD SHORTLY

Objective

The main objective of this tutorial is to help you to get Your Current Location using the GPS system.

 

 

Step 1 First create new Project with the following permission.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" />

In MarshMallow, you have to check permissions at runtime.

 

Step 2 Location Manager

Then we need LocationManager in our Main Activity class for Location Service and also need LocationListener for the retrieving new Locations.

LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
LocationListener locListener = new MyLocationListener();
 

Step 3 LocationListener

Now, create a new class named MyLocationListener in the Main Activity Class.

public class MyLocationListener implements LocationListener {
 
@Override
public void onLocationChanged(Location location) {
 
// Retrieving Latitude
location.getLatitude();
// Retrieving getLongitude
location.getLongitude();
 
textInfo.setText("");
String text = "My Current Location is:\nLatitude = "
+ location.getLatitude() + "\nLongitude = "
+ location.getLongitude();
textInfo.setText(text);
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT)
.show();
 
// set Google Map on webview
String url = "http://maps.google.com/staticmap?center="
+ location.getLatitude() + "," + location.getLongitude()
+ "&zoom=14&size=512x512&maptype=mobile/&markers="
+ location.getLatitude() + "," + location.getLongitude();
position.loadUrl(url);
}
 
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(getApplicationContext(), "GPS Disabled",
Toast.LENGTH_SHORT).show();
}
 
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(getApplicationContext(), "GPS Enabled",
Toast.LENGTH_SHORT).show();
}
 
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
 
}
 
}

For more information about LocationListner please follow the link:

I hope you enjoy this tutorial and it would be helpful to you.

Got an Idea of Android App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Android App Development Company in India.

An entrepreneur who has founded 2 flourishing software firms in 7 years, Tejas is keen to understand everything about gaming - from the business dynamics to awesome designs to gamer psychology. As the founder-CEO of a company that has released some very successful games, he knows a thing or two about gaming. He shares his knowledge through blogs and talks that he gets invited to.

face mask Belial The Demon Headgear Pocket Staff Magic