How to Obtain Latitude and Longitude in Android

☆樱花仙子☆ 提交于 2019-12-04 17:32:29
Udaykiran

edited : Network and also GPS Provider Location

Yes we cam...try this

LocationManager manager = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE);
manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

// additionally (you have to implement LocationListener)
manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0.0f, new LocationListener() ...)

After location you can use in locationlistener...

 @Override
    public void onLocationChanged(Location location) {                          
         Log.d("a","onLocationChanged: lat="+location.getLatitude());
         Log.d("a","onLocationChanged: lat="+location.getLongitude());                 
    }

hope it helps..

Yes you can. Have a look at the documentation

When you have a Location from the system. you can use methods getLongitude() and getLatitude()

For a full example have a look at this code - lines 122-124 to set up receiving updates and lines 201-209 to get the Location.

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