how to latitude and longitude with name of current location in android studio?

 

Latitude and Longitude are the units that represent the coordinates at geographic coordinate system. To make a search, use the name of a place, city, state, or address, or click the location on the map to find lat long coordinates.

AndroidManifest.xml

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

LayOut
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_location_Source"
android:layout_width="wrap_content"
android:layout_height="40dp"

android:layout_alignParentRight="true"
android:layout_marginTop="27dp"

android:layout_marginBottom="10dp"
android:onClick="onLocationSource"
android:src="@drawable/ic_location"
android:tint="#fff"

app:backgroundTint="@color/black"
app:fabCustomSize="30dp"
app:fabSize="auto"

/>
dependencies {
        //IMPORTANT: make sure to use the newest version. 11.0.1 is old AF
        compile 'com.google.android.gms:play-services-location:11.0.1
    }
Activity

LocationManager locationManager;


FabSource = (FloatingActionButton) findViewById(R.id.fab_location_Source);

FabSource.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);


if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
buildAlertMessageNoGps();

} else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
getLocationSource();
}

}
});
 public void onStatusChanged(String provider, int status, Bundle extras) {
        // called when the location provider status changes. Possible status: OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE or AVAILABLE.
    }
    public void onProviderEnabled(String provider) {
        // called when the location provider is enabled by the user
    }
    public void onProviderDisabled(String provider) {
        // called when the location provider is disabled by the user. If it is already disabled, it's called immediately after requestLocationUpdates
    }
    
    public void onLocationChanged(Location location) {
        double latitute = location.getLatitude();
        double longitude = location.getLongitude();
        // do whatever you want with the coordinates
    }



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad