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

◇◆丶佛笑我妖孽 提交于 2019-11-27 19:27:56

You have a mistake in your manifest file. Correct one is:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Santosh Kumar

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

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!

In your android manifest did you set the permissions?

android.permission.ACCESS_FINE_LOCATION

As far as only getting (0,0) co-ords you're probably using the emulator. If you're using eclipse go to the emulator control and at the bottom you can send the fake co-ords to the device

Noman

You are not using the correct permission. The correct one is:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

By the way, your demand can only be fulfilled by:

<using-permission android:name="ACCESS_FINE_LOCATION" />

So there is no need for ACCESS_COARSE_LOCATION

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!