使用这种技术:
LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
boolean network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Location location;
if(network_enabled){
location = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if(location!=null){
longitude = location.getLongitude();
latitude = location.getLatitude();
}
}
在这种情况下,您甚至不需要在GPS上只有您的移动网络才能这样做.
不要忘记在Manifest中给予以下许可: