我正在研究在Android手机(三星Galaxy GT 15801和Micromax A60)中使用GPS绘制旅行方式。但有时它给了我错误的lat& long。我在印度,但它显示我在阿拉伯海中部的某个地方,并在一段时间后显示正确的纬度和长度。帮我解决这个问题。
答案 0 :(得分:0)
在活动中使用
LocationManager mlocManager = (LocationManager)getSystemService(this.LOCATION_SERVICE);
LocationListener mlocListener = new GetGPS(LoginPanel.this);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = mlocManager.getBestProvider(criteria, true);
mlocManager.requestLocationUpdates(provider, 0, 0, mlocListener);
只需将其用作单独的类
public class GetGPS implements LocationListener
{
GlobalVariable globalInstance;
public GetGPS(Context context)
{
}
public void onLocationChanged(Location location)
{
//location.getLatitude();
//location.getLongitude();
}
public void onProviderDisabled(String provider)
{
//alertDialog.showMessage("Please Turn On your GPS", "GPS Turned Off");
}
public void onProviderEnabled(String provider)
{
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}