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

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

    In Kotlin using LocationManager class you can pass the required location provider like:

    val location = Location(LocationManager.NETWORK_PROVIDER) // OR GPS_PROVIDER based on the requirement
    location.latitude = 42.125
    location.longitude = 55.123
    

提交回复
热议问题