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

前端 未结 4 1724
花落未央
花落未央 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:30

    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);
    

提交回复
热议问题