我没有在三星S3中获得lat和long。在其他设备中我的代码工作正常并获得正确的lat和long.Below是我的代码来获得lat和long。
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中执行,并且相同的代码在Samsung S3设备中不起作用。在其他设备中它工作正常。我在其他设备中得到正确的lat和long。请帮帮我解决这个问题..