Android: how to initialize a variable of type "Location" (distinguishing it from zero)

I want to check the code that I wrote, and for this I need to build a variable of type Location and give it a long / lat value, but I'm not sure how I will do it. Any ideas?

+47
android geolocation
Jun 06 '10 at 18:16
source share
3 answers

The API documentation is perfectly understandable. First create a new instance of the location:

Location loc = new Location("dummyprovider"); 

And then use the configuration methods to set the necessary location parameters, for example:

 loc.setLatitude(20.3); loc.setLongitude(52.6); 
+85
Jun 06 '10 at 18:25
source share
 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 use the initial values

 double lat = object.getLatitude(); double lng = object.getLongitude(); 
+3
Dec 03 '15 at 9:52
source share

You can write a method:

 Location createNewLocation(double longitude, double latitude) { Location location = new Location("dummyprovider"); location.setLongitude(longitude); location.setLatitude(latitude); return location; } 

And then call it:

 Location myLoc = createNewLocation(dLong, dLati); 

Or you can use the line with Double.parse ():

 Location myLoc = createNewLocation(Double.parse("s.Long"), Double.parse("s.Lati")); 
+1
Oct. 16 '16 at 21:01
source share



All Articles