问题
I have a simple android code to send GPS location to a database periodically via a web service. For testing purpose I set the minTime to 2000ms.
lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
ll=new SpeedoActionListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,2000, 0,ll);
But...
- when my phone is not moving, still it inserts different longitude and latitude values to the database.
- Even I disabled GPS it sends different longitude latitude to the database untill I close the connection between my phone and the laptop.
Web service is hosted on IIS7 and my phone and laptop connected via wi-fi
Though my phone is not moving, why it sends different locations?
private class SpeedoActionListener implements LocationListener
{
String result=null;
@Override
public void onLocationChanged(Location location) {
if(location!=null) {
lati=location.getLatitude();
longi=location.getLongitude();
String mylati=Double.toString(lati);
String mylongi=Double.toString(longi);
WebServiceCaller obj=new WebServiceCaller();
result=obj.sendLocationData(mylongi, mylati);
resultText=(TextView)findViewById(R.id.result);
resultText.setText(result);
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
回答1:
In low accuracy settings, data will receive from Wifi networks. Check Setting/Location/Use Wireless networks check box on your android phone.
回答2:
Android uses GPS when available, but does not rely only on GPS. The internals for when it uses what data sources is a complex subject, as described in the guide topic Obtaining User Location. The location changes may come, for instance, from the phone switching strategies to save battery life.
回答3:
GPS has inherent imprecision, so I would expect slight variations. I don't know why it would keep changing when you turn of GPS, though (as noted by the other answers, it's probably using an alternate source like WiFi triangulation).
来源:https://stackoverflow.com/questions/9858788/my-phone-is-not-moving-but-gps-data-still-changing