Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Android Location Object

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 ?

like image 561
sisko Avatar asked Feb 09 '11 13:02

sisko


People also ask

How will you create location manager object?

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.

What is a location object in Android?

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.

How do you create a location using latitude and longitude?

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.

How can I add current location in Android?

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.


1 Answers

Assuming you refer to android.location.Location use the constructor which takes a provider string and set it to whatever you want.

like image 144
Reuben Scratton Avatar answered Sep 29 '22 10:09

Reuben Scratton