我在三星 S3 中没有得到经纬度。在其他设备上,我的代码工作正常,并且得到了正确的经度和经度。下面是我获取经度和经度的代码。
public class MainActivity extends Activity {
TextView textView1;
Location currentLocation;
double currentLatitude,currentLongitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView1 = (TextView) findViewById(R.id.textView1);
findLocation();
}
public void findLocation() {
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateLocation(location,currentLatitude,currentLongitude);
Toast.makeText(
MainActivity.this,
String.valueOf(currentLatitude) + "\n"
+ String.valueOf(currentLongitude), 5000)
.show();
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
void updateLocation(Location location,double currentLatitude,double currentLongitude) {
currentLocation = location;
this.currentLatitude = currentLocation.getLatitude();
this.currentLongitude = currentLocation.getLongitude();
textView1.setText(String.valueOf(this.currentLatitude) + "\n"
+ String.valueOf(this.currentLongitude));
}
}
在上面的代码中,onLocationChanged() 方法没有在 S3 中执行,并且相同的代码在三星 S3 设备中不起作用。在其他设备中它工作正常。我在其他设备中得到正确的纬度和经度。请帮我整理一下这个问题..