android gps开发(mrGPS源代码)
来源:互联网 发布:郑州网络鲜花订购 编辑:程序博客网 时间:2024/05/16 11:44
file:AndroidManifest.xml
<uses-permission android:name="android.permission.RESTART_PACKAGES" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
file:main.java
package com.mrsoft.mrgps.app.mr;import android.app.Activity;import android.app.ActivityManager;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.Context;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.location.Criteria;import android.location.Location;import android.location.LocationListener;import android.location.LocationManager;import android.os.Bundle;import android.view.KeyEvent;import android.view.Menu;import android.view.MenuItem;import android.widget.TextView;import android.widget.Toast;public class main extends Activity {private TextView tv;private LocationManager lm;private Criteria criteria;private Location location; private final static int MENU_ABOUT = Menu.FIRST; private final static int MENU_EXIT = Menu.FIRST+1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv = (TextView)findViewById(R.id.tv); lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { Toast.makeText(this, "GPS已关闭,请手动开启GPS后再试!", Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(this, "GPS定位中...", Toast.LENGTH_SHORT).show(); } criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE);// 设置精确度 criteria.setAltitudeRequired(true);// 设置请求海拔 criteria.setBearingRequired(true);// 设置请求方位 criteria.setCostAllowed(true);// 设置允许运营商收费 criteria.setPowerRequirement(Criteria.POWER_LOW); // 低功耗 String provider = lm.getBestProvider(criteria, true); location = lm.getLastKnownLocation(provider); newLocalGPS(location); // 监听1秒一次 忽略位置变化 lm.requestLocationUpdates(provider, 1*1000, 0, new locationListener()); } class locationListener implements LocationListener {@Overridepublic void onLocationChanged(Location location) {// TODO Auto-generated method stubnewLocalGPS(location);}@Overridepublic void onProviderDisabled(String provider) {// TODO Auto-generated method stubnewLocalGPS(null);}@Overridepublic void onProviderEnabled(String provider) {// TODO Auto-generated method stub}@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {// TODO Auto-generated method stub} } private void newLocalGPS(Location location) { if (location!=null) { double latitude = location.getLatitude(); //精度 double longitude = location.getLongitude(); // 纬度 double speed = location.getSpeed();// 速度 double altitude = location.getAltitude();// 海拔 double bearing = location.getBearing();// 方位 tv.setText("精度"+latitude+'\n'+ "纬度"+longitude+'\n'+ "速度"+speed+"m/s"+'\n'+ "海拔"+altitude+"m"+'\n'+ "方位"+bearing+'\n'); } else { // 未获取地理信息位置 tv.setText("地理信息位置未知或正在获取地理信息位置中..."); } } @Overridepublic boolean onCreateOptionsMenu(Menu menu) {// TODO Auto-generated method stub menu.add(0, MENU_ABOUT, 1, "关于"); menu.add(0, MENU_EXIT, 2, "退出");return super.onCreateOptionsMenu(menu);}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// TODO Auto-generated method stubswitch (item.getItemId()){case MENU_ABOUT: AlertDialog.Builder bd = new Builder(main.this); bd.setMessage("mrGPS.apk\n版本:1.0\n作者:mrandexe"); bd.setTitle("关于"); bd.setPositiveButton("确认", new OnClickListener(){ @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub arg0.dismiss(); } }); bd.create().show(); break;case MENU_EXIT:exit();break;}return super.onOptionsItemSelected(item);}@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode==KeyEvent.KEYCODE_BACK && event.getRepeatCount()==0) { exit(); return true; } return super.onKeyDown(keyCode, event); } private void exit() { AlertDialog.Builder builder = new Builder(main.this); builder.setMessage("确认退出吗?"); builder.setTitle("提示"); builder.setPositiveButton("确认", new OnClickListener(){ @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub arg0.dismiss(); ActivityManager actMgr = (ActivityManager)getSystemService(ACTIVITY_SERVICE); actMgr.restartPackage(getPackageName()); } }); builder.setNegativeButton("取消", new OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); } }); builder.create().show(); }}
file:main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text="TextView" android:layout_width="wrap_content" android:id="@+id/tv" android:layout_height="wrap_content"></TextView></LinearLayout>
- android gps开发(mrGPS源代码)
- android GPS开发
- Android系统Gps开发
- Android开发---GPS定位
- Android GPS应用开发
- 更新Android版GPS定位源代码
- 更新Android版GPS定位源代码
- Android GPS 开发相关API
- android gps开发必备资料
- PhoneGap android开发:GPS定位
- Android之GPS开发总结
- android源代码开发环境
- Android手机开发:获取GPS信息
- android用户定位GPS开发(一)
- Android 定位系统(GPS)开发基础
- android开发之GPS定位详解
- Android开发之GPS获取当前位置信息
- Android实现定位---GPS应用开发
- 动态组装sql(解决where1=1低效的方案)
- #pragma once 与 #ifndef 一个利用文件检查,一个利用宏检查
- 正确区分LJMP、AJMP、SJMP、JMP指令
- 利用div+css生成简单的导航菜单,简单实用
- 2011-7-20 10:06:59
- android gps开发(mrGPS源代码)
- 伤不起的 强连通+二分匹配 hdu 3861
- android (15)
- 内部排序的分类
- android学习笔记之Animations
- android学习笔记之JSON
- C#调用C++DLL时的编码转换-编码、字符集
- 缺席的逻辑训练之中印教育比较
- 使用DEF文件来生成DLL与Lib