我想得到用户位置,这里有Gps 这是我的代码
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("
");
sb.append(address.getLocality()).append("
");
sb.append(address.getPostalCode()).append("
");
sb.append(address.getCountryName());
}
String a="Latitude:"+lat+"
Longtitude:"+longt+"
Address:"+sb.toString();
t.setText(a);
}
catch(Exception e)
{
t.setText("Error.
"+e.toString());
}
}
我给予所有许可;
2.2.3 装置是 HTC 野火 S
代码代码不会丢出错误,但它也没有作用
有人知道吗?