Android - How to get current location (latitude and longitude)?

后端 未结 4 1295
粉色の甜心
粉色の甜心 2020-12-05 05:33

I am using the following code to get the current location namely (latitude and longitude), but I am not getting current location (latitude and longitude).

Anyone kno

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 06:07

    You have to send location fix to emulator,as emulator is software you need to provide with location fix.

    If you are using eclipse go to

    Window -> Show view -> Other

    Select Android tab and search for emulator control.
    After u see emulator control window navigate to location controls.
    As u see in below pic

    sending loc fix

    After you have sent loc fix you can use

    Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    

    Where lm is LocationManager object so 90% of work is done ;)

    Cheers!

提交回复
热议问题