Android: How To Initialize A Variable Of Type "Location" (other Than Making It Equal To Null)
Answer :
The API documentation is quite clear on this. First create a new Location instance:
Location loc = new Location("dummyprovider"); And then use the setter methods to set the location parameters you need, e.g.:
loc.setLatitude(20.3); loc.setLongitude(52.6); Location object = new Location("service Provider"); it will create an object of Type Location that contains the initial Latitude and Longitude at location '0' to get the initial values use
double lat = object.getLatitude(); double lng = object.getLongitude(); In Kotlin using LocationManager class you can pass the required location provider like:
val location = Location(LocationManager.NETWORK_PROVIDER) // OR GPS_PROVIDER based on the requirement location.latitude = 42.125 location.longitude = 55.123
Comments
Post a Comment