0
GPS獲取用戶的位置我wantto來到這裏與GPS用戶的位置是我的代碼麻煩通過從HTC野火S
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t=(TextView)findViewById(R.id.textView1);
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
}
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
double lat=location.getLatitude();
double longt= location.getLongitude();
Geocoder gc=new Geocoder(getApplicationContext(),Locale.getDefault());
try
{
List <Address> adresses=gc.getFromLocation(lat, longt, 1);
StringBuilder sb=new StringBuilder();
if(adresses.size()>0)
{
Address address=adresses.get(0);
for(int i=0;i<address.getMaxAddressLineIndex();i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
String a="Latitude:"+lat+"\nLongtitude:"+longt+"\nAddress:"+sb.toString();
t.setText(a);
}
catch(Exception e)
{
t.setText("Error.\n"+e.toString());
}
}
,我給了所有權限;
平臺就是Android 2.2.3和設備是HTC野火S
代碼不會引發一個錯誤,但它不是工作要麼
有沒有人有任何想法?
你能定義「不工作」?您是否等待足夠長的GPS定位?不會改變嗎?它怎麼不起作用? – Sam
噸不會改變,日誌貓什麼都不顯示,我等待20-30分鐘的GPS ...設備頂部的GPS圖標閃爍,並顯示設備可以獲得GPS信號 – dextererer