GPS技术(一)
1 //获取所有的provider
2 public class MainActivity extends ActionBarActivity {
3 ListView mprovider;
4 LocationManager mlManager;
5
6 @Override
7 protected void onCreate(Bundle savedInstanceState) {
8 super.onCreate(savedInstanceState);
9 setContentView(R.layout.fragment_main);
10 mprovider = (ListView) findViewById(R.id.listView1);
11 // 获得LocationManager对象
12 mlManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
13 // 获取所有的Locationprovider的名称
14 List<String> providerNames = mlManager.getAllProviders();
15
16 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
17 android.R.layout.simple_list_item_1, providerNames);
18 mprovider.setAdapter(adapter);
19 }
20
21 }
1 //根据条件获得Locationprovider
2 public class MainActivity extends ActionBarActivity {
3 ListView mprovider;
4 LocationManager mlManager;
5
6 @Override
7 protected void onCreate(Bundle savedInstanceState) {
8 super.onCreate(savedInstanceState);
9 setContentView(R.layout.fragment_main);
10 mprovider = (ListView) findViewById(R.id.listView1);
11 mlManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
12 // 创建一个LocationProvider的过滤条件
13 Criteria criteria = new Criteria();
14 // 设置要求LocationProvider必须是免费的
15 criteria.setCostAllowed(false);
16 // 设置要求ocationProvider能提供高度信息----测海拔
17 criteria.setAltitudeRequired(true);
18 // 设置要求ocationProvider能提供方向信息----方向
19 criteria.setBearingRequired(true);
20 List<String> providerName = mlManager.getProviders(criteria, true);
21 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
22 android.R.layout.simple_list_item_1, providerName);
23 mprovider.setAdapter(adapter);
24 }
25
26 }