How do I get the current GPS location programmatically in Android?

前端 未结 22 2596
梦谈多话
梦谈多话 2020-11-21 04:42

I need to get my current location using GPS programmatically. How can i achieve it?

22条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 05:02

    I will recommend using Smart Location Library
    Very simple to use and it wraps the location logic nicely.

    For starting the location service:

    SmartLocation.with(context).location()
        .start(new OnLocationUpdatedListener() { ... });
    

    If you just want to get a single location (not periodic) you can just use the oneFix modifier. Example:

    SmartLocation.with(context).location()
        .oneFix()
        .start(new OnLocationUpdatedListener() { ... });
    

提交回复
热议问题