简体   繁体   中英

How to Obtain Latitude and Longitude in Android

如果无法使用GPS,如何从移动设备获取纬度和经度...我的手机通过wifi和gprs连接建立了互联网连接。...我们可以从中获取经度和纬度吗?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM