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

前端 未结 4 1825
花落未央
花落未央 2021-02-11 12:20

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. An

4条回答
  •  后悔当初
    2021-02-11 12:40

    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 string with Double.parse():

    Location myLoc = createNewLocation(Double.parse("s.Long"), Double.parse("s.Lati"));
    

提交回复
热议问题