0% found this document useful (0 votes)
5 views5 pages

Task10 Currentlocation

The MyLocationActivity class is an Android application that utilizes Google Maps to display the user's current location. It requests location permissions and updates the map with the user's latitude and longitude, displaying an address marker. The user can switch between different map types such as normal, satellite, terrain, hybrid, and none using buttons in the UI.

Uploaded by

Onkar Mantri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Task10 Currentlocation

The MyLocationActivity class is an Android application that utilizes Google Maps to display the user's current location. It requests location permissions and updates the map with the user's latitude and longitude, displaying an address marker. The user can switch between different map types such as normal, satellite, terrain, hybrid, and none using buttons in the UI.

Uploaded by

Onkar Mantri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MyLocationActivity.

java

package [Link];

import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];

public class MyLocationActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;


private ActivityMyLocationBinding binding;

LocationManager locationManager;
public static final int Request_Location_Permission = 1;
double latitude,longitude;
String address;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);

binding = [Link](getLayoutInflater());
setContentView([Link]());

// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById([Link]);
[Link](this);

locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

//checking permission is granted or not


if ([Link]([Link],
[Link].ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED)
{
[Link]([Link],
new
String[]{[Link].ACCESS_FINE_LOCATION},Request_Location_Permission);
}
else if ([Link]([Link],
[Link].ACCESS_COARSE_LOCATION)!=
PackageManager.PERMISSION_GRANTED)
{
[Link]([Link],
new
String[]{[Link].ACCESS_COARSE_LOCATION},Request_Location_Permission);
}

if ([Link](LocationManager.NETWORK_PROVIDER))
{
[Link](LocationManager.NETWORK_PROVIDER,
5000, 10,
new LocationListener() {
@Override
public void onLocationChanged(@NonNull Location location) {
latitude = [Link]();
longitude = [Link]();
Geocoder geocoder = new Geocoder([Link]);

try {
List<Address> addressList = [Link](latitude,
longitude, 1);

address = [Link](0).getAddressLine(0)+","+
[Link](0).getLocality()+","+
[Link](0).getCountryName();

LatLng mycurrentlocation = new LatLng(latitude, longitude);

[Link]();

[Link](new
MarkerOptions().position(mycurrentlocation).title(address));

[Link]([Link](mycurrentlocation,18),
5000,null);

} catch (IOException e) {
throw new RuntimeException(e);
}

}
});
} else if ([Link](LocationManager.GPS_PROVIDER)) {
[Link](
LocationManager.GPS_PROVIDER,
5000, 10,
new LocationListener() {
@Override
public void onLocationChanged(@NonNull Location location) {
latitude = [Link]();
longitude = [Link]();

Geocoder geocoder = new Geocoder([Link]);


try {
List<Address> addressList1 = [Link](latitude,
longitude,1);

address = [Link](0).getAddressLine(0)+","+
[Link](0).getLocality()+","+
[Link](0).getCountryName();

LatLng mycurrentlocation1 = new LatLng(latitude, longitude);

[Link]();

[Link](new
MarkerOptions().position(mycurrentlocation1).title(address));
[Link]([Link](mycurrentlocation1,18),
5000,null);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
);

}
}

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

/* LatLng mylocation= new LatLng(20.155077, 76.588398);


[Link](new MarkerOptions().position(mylocation).title("My Loction"));
// [Link]([Link](mylocation));
[Link]([Link](mylocation,10),2000,null);
[Link](new CircleOptions()
.center(mylocation)
.fillColor([Link]("#00000000"))
.strokeColor([Link]("#000000"))
.radius(150));

LatLng clglocation = new LatLng(21.297631,77.517845);


[Link](new MarkerOptions().position(clglocation).title("Government Polytechnic
Achalpur"));
[Link](new PolylineOptions()
.add(mylocation,clglocation)
.color([Link])
.width(5));*/

[Link](v ->
[Link](GoogleMap.MAP_TYPE_NORMAL));
[Link](v ->
[Link](GoogleMap.MAP_TYPE_SATELLITE));
[Link](v ->
[Link](GoogleMap.MAP_TYPE_TERRAIN));
[Link](v -> [Link](GoogleMap.MAP_TYPE_HYBRID));
[Link](v -> [Link](GoogleMap.MAP_TYPE_NONE));
}
}

OUTPUT

You might also like