I am using the Geocoder class to fetch multiple location objects by using the following code:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 3);
Address[] addresses_array = new Address[addresses.size()];
addresses.toArray(addresses_array);
for( int i = 0; i < addresses_array.length; i++ ){
//create location object here
locOBJ.setLatitude(LATITUDE);
locOBJ.setLongitude(LONGITUDE);
}
In addition, inside the forloop, I am trying to dymanically create location objects to add to an array;
How can I create blank location objects ?
First, create a Location Manager object by calling the getSystemService() method and LOCATION_SERVICE as an argument. Call getBestProvider() to get the location in the form of a string. Now the provider to the getLastKnownLocation() as an argument to get the location.
android.location.Location. A data class representing a geographic location. A location consists of a latitude, longitude, timestamp, accuracy, and other information such as bearing, altitude and velocity.
To find a location using its latitude and longitude on any device, just open Google Maps. On your phone or tablet, start the Google Maps app. On a computer, go to Google Maps in a browser. Then enter the latitude and longitude values in the search field — the same one you would ordinarily use to enter an address.
There are two ways to get the current location of any Android device: Android's Location Manager API. Fused Location Provider: Google Play Services Location APIs.
Assuming you refer to android.location.Location
use the constructor which takes a provider string and set it to whatever you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With