Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to initialize a variable of type "Location" (other than making it equal to null)

I'm looking to test some code I've written and to do so I need to construct a variable of type Location and to give it a long / lat value but I'm unsure how I would do so. Any ideas?

like image 556
Skizit Avatar asked Jun 06 '10 18:06

Skizit


People also ask

How we can declare variable in Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken text view to show global variable.

How do you initialize variables in flutter?

Defining Variables One of many ways, and the simplest way, to define a variable in Dart is using the var key word. var message = 'Hello, World'; This example creates a variable called message , and also initializes the variable with a String value of Hello, World .


2 Answers

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();
like image 20
Atta Ullah Avatar answered Oct 21 '22 15:10

Atta Ullah


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);
like image 110
Matti Virkkunen Avatar answered Oct 21 '22 16:10

Matti Virkkunen