易采站长站为您分析Android实现GPS定位实例,对关键操作部份给出代码示例并做了一定的注释,需要的朋友可以参考下
通过GPS取得的是一个Location类型的经纬度, 可以转换为两个Double 纬度和经度.
纬度: 23.223871812820435
纬度: 113.58986039161628
首先创建一个TextView和两个Button
- <TextView android:id="@+id/text"
- android:layout_width="fill_parent" android:layout_height="wrap_content" />
- <Button
- android:id="@+id/btnStart" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:text="定位" />
- <Button android:id="@+id/btnStop"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:text="停止" />
然后添加主Activity的代码
Location 是存放经纬度的一个类型
LocationManager是位置管理服务类型
- private Button btnStart; private Button btnStop;
- private TextView textView; private Location mLocation;
- private LocationManager mLocationManager; /** Called when the activity is first created. */
- @Override public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState); setContentView(R.layout.main);










