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