我写了以下代码,返回我当前的位置地址.但是只有手动打开我的Wifi才能获得这些值.但我想打开Gps并从GPS获取我的地址,而不是从Wifi.有人请告诉我这段代码中要修改的是什么.以下是用于查找当前地址的代码.提前致谢.
public String myloc()
{
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager.getBestProvider(criteria, true);
// Update the GUI with the last known
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null)
{
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
Geocoder gc = new Geocoder(this, Locale.getDefault());
try
{
List<Address> addresses = gc.getFromLocation(lat, lng, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0)
{
Address address = …
Run Code Online (Sandbox Code Playgroud)