package zfy.mygps;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Mygps extends Activity {
protected static final String TAG = null;
//位置类
private Location location;
// 定位管理类
private LocationManager locationManager;
private String provider;
//监听卫星变量
private GpsStatus gpsStatus;
Iterable<GpsSatellite> allSatellites;
float satellitedegree[][] = new float[24][3];
float alimuth[] = new float[24];
float elevation[] = new float[24];
float snr[] = new float[24];
private boolean status=false;
protected Iterator<GpsSatellite> Iteratorsate;
private float bear;
//获取手机屏幕分辨率的类
private DisplayMetrics dm;
paintview layout;
Button openbutton;
Button closebutton;
TextView latitudeview;
TextView longitudeview;
TextView altitudeview;
TextView speedview;
TextView timeview;
TextView errorview;
TextView bearingview;
TextView satcountview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
findview();
openbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(!status)
{
openGPSSettings();
getLocation();
status = true;
}
}
});
closebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
closeGps();
}
});
}
private void findview() {
// TODO Auto-generated method stub
openbutton = (Button)findViewById(R.id.open);
closebutton = (Button)findViewById(R.id.close);
latitudeview = (TextView)findViewById(R.id.latitudevalue);
longitudeview = (TextView)findViewById(R.id.longitudevalue);
altitudeview = (TextView)findViewById(R.id.altitudevalue);
speedview = (TextView)findViewById(R.id.speedvalue);
timeview = (TextView)findViewById(R.id.timevalue);
errorview = (TextView)findViewById(R.id.error);
bearingview = (TextView)findViewById(R.id.bearvalue);
layout=(zfy.mygps.paintview)findViewById(R.id.iddraw);
satcountview = (TextView)findViewById(R.id.satellitevalue);
}
protected void closeGps() {
// TODO Auto-generated method stub
// dm = new DisplayMetrics();
// getWindowManager().getDefaultDisplay().getMetrics(dm);
// heightp = dm.heightPixels;
// widthp = dm.widthPixels;
// alimuth[0] = 60;
// elevation[0] = 20;
// snr[0] = 60;
// alimuth[1] = 260;
// elevation[1] = 10;
// snr[1] = 50;
// layout.redraw(240,alimuth,elevation,snr, widthp,heightp, 2);
if(status == true)
{
locationManager.removeUpdates(locationListener);
locationManager.removeGpsStatusListener(statusListener);
errorview.setText("");
latitudeview.setText("");
longitudeview.setText("");
speedview.setText("");
timeview.setText("");
altitudeview.setText("");
bearingview.setText("");
satcountview.setText("");
status = false;
}
}
//定位监听类负责监听位置信息的变化情况
private final LocationListener locationListener = new LocationListener()
{
@Override
public void onLocationChanged(Location location)
{
// 获取GPS信息 获取位置提供者provider中的位置信息
// location = locationManager.getLastKnownLocation(provider);
// 通过GPS获取位置
updateToNewLocation(location);
//showInfo(getLastPosition(), 2);
}
@Override
public void onProviderDisabled(String arg0)
{
}
@Override
public void onProviderEnabled(String arg0)
{
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2)
{
updateToNewLocation(null);
}
};
//添加监听卫星
private final GpsStatus.Listener statusListener= new GpsStatus.Listener(){
@Override
public void onGpsStatusChanged(int event) {
// TODO Auto-generated method stub
//获取GPS卫星信息
gpsStatus = locationManager.getGpsStatus(null);
switch(event)
{
case GpsStatus.GPS_EVENT_STARTED:
break;
//第一次定位时间
case GpsStatus.GPS_EVENT_FIRST_FIX:
break;
//收到的卫星信息
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
DrawMap();
break;
case GpsStatus.GPS_EVENT_STOPPED:
break;
}
}
};
private int heightp;
private int widthp;
private void openGPSSettings()
{
// dm = new DisplayMetrics();
// getWindowManager().getDefaultDisplay().getMetrics(dm);
// heightp = dm.heightPixels;
// widthp = dm.widthPixels;
// alimuth[0] = 60;
// elevation[0] = 70;
// snr[0] = 60;
// alimuth[1] = 260;
// elevation[1] = 10;
// snr[1] = 50;
// layout.redraw(50,alimuth,elevation,snr, widthp,heightp, 2);
// 获取位置管理服务
locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
if (locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER))
{
Toast.makeText(this, "GPS模块正常", Toast.LENGTH_SHORT).show();
return;
}
status = false;
Toast.makeText(this, "请开启GPS!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivityForResult(intent,0); //此为设置完成后返回到获取界面 }
}
protected void DrawMap() {
// TODO Auto-generated method stub
int i = 0;
//获取屏幕信息
dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
heightp = dm.heightPixels;
widthp = dm.widthPixels;
//获取卫星信息
allSatellites = gpsStatus.getSatellites();
Iteratorsate = allSatellites.iterator();
while(Iteratorsate.hasNext())
{
GpsSatellite satellite = Iteratorsate.next();
alimuth[i] = satellite.getAzimuth();
elevation[i] = satellite.getElevation();
snr[i] = satellite.getSnr();
i++;
}
satcountview.setText(""+i);
layout.redraw(bear,alimuth,elevation,snr, widthp,heightp, i);
layout.invalidate();
}
private void getLocation()
{
// 查找到服务信息 位置数据标准类
Criteria criteria = new Criteria();
//查询精度:高
criteria.setAccuracy(Criteria.ACCURACY_FINE);
// 是否查询海拔:是
criteria.setAltitudeRequired(true);
//是否查询方位角:是
criteria.setBearingRequired(true);
//是否允许付费
criteria.setCostAllowed(true);
// 电量要求:底
criteria.setPowerRequirement(Criteria.POWER_LOW);
//是否查询速度:是
criteria.setSpeedRequired(true);
provider = locationManager.getBestProvider(criteria, true);
// 获取GPS信息 获取位置提供者provider中的位置信息
location = locationManager.getLastKnownLocation(provider);
// // 通过GPS获取位置
updateToNewLocation(location);
//
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 32 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/5df8bff20ad645abb899a1a8333a748d_weixin_42651281.jpg!1)
小波思基
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)