Android之百度地图(一)

<resources>
              
                  <!--
                      Base application theme, dependent on API level. This theme is replaced
                      by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
                  -->
                  <style name="AppBaseTheme" parent="android:Theme.Light">
                      <!--
                          Theme customizations available in newer API levels can go in
                          res/values-vXX/styles.xml, while customizations related to
                          backward-compatibility can go here.
                      -->
                  </style>
              
                  <!-- Application theme. -->
                  <style name="AppTheme" parent="AppBaseTheme">
                      <!-- All customizations that are NOT specific to a particular API-level can go here. -->
                  </style>
      </resources>

先上代码,先弄基础的样式AppBaseTheme,将其设置成android:Theme.Light
更多的样式如下,再将其弄填入AppTheme中。在res/values/style.xml的路径之下
在这里插入图片描述

窗口主题设置:(这里主要对于Activity设置,用到系统自动主题内容)
•android:theme=”@android:style/Theme.Dialog” 将一个Activity显示为能话框模式
•android:theme=”@android:style/Theme.NoTitleBar” 不显示应用程序标题栏
•android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”
不显示应用程序标题栏,并全屏 •android:theme=”Theme.Light” 背景为白色
•android:theme=”Theme.Light.NoTitleBar” 白色背景并无标题栏
•android:theme=”Theme.Light.NoTitleBar.Fullscreen” 白色背景,无标题栏,全屏
•android:theme=”Theme.Black” 背景黑色
•android:theme=”Theme.Black.NoTitleBar” 黑色背景并无标题栏
•android:theme=”Theme.Black.NoTitleBar.Fullscreen” 黑色背景,无标题栏,全屏
•android:theme=”Theme.Wallpaper” 用系统桌面为应用程序背景
•android:theme=”Theme.Wallpaper.NoTitleBar” 用系统桌面为应用程序背景,且无标题栏
•android:theme=”Theme.Wallpaper.NoTitleBar.Fullscreen”
用系统桌面为应用程序背景,无标题栏,全屏 •android:theme=”Translucent” 半透明
•android:theme=”Theme.Translucent.NoTitleBar”
•android:theme=”Theme.Translucent.NoTitleBar.Fullscreen”
•android:theme=”Theme.Panel” •android:theme=”Theme.Light.Panel”

在application中按照如下格式: android:theme="@style/AppTheme"

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.gps_demo.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

必须要在Manifest文件中申请这三个权限 :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

Gps定位开发
1.获取位置管理器的实例
2.创建位置变化的监听器
{
1.位置变化时候的监听器 重写方法public void onLocationChanged(Location location)
double time=location.getTime();//获得卫星上的时间 double 类型 需要放在try中
SimpleDateFormat format=new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);//自定义创建日期格式
String timeNow=format.format(time);//应用此格式
2.卫星状态监听器 包括里面很重要的迭代器(用来遍历的)
迭代器的用法 迭代器的类型 对象

Iterator<GpsSatellite> it=status.getSatellites().iterator();

然后再遍历 代码如下
在这里插入图片描述

3.将上诉的两个监听器添入位置管理器中

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,   //使用GPS定位
5000,  //时间分辨率ms
0,   //距离分辨率m
ll   //位置变化监听器
); //添加位置变化监听器   
	locationManager.addGpsStatusListener(statusListener);  //添加卫星状态监听器

}

private void initGPSListener()
	{
		final LocationManager locationManager=(LocationManager)
				this.getSystemService(Context.LOCATION_SERVICE);//获取位置管理器实例
		LocationListener ll=new LocationListener(){//位置变化监听器
			@Override	//当位置变化时触发
			public void onLocationChanged(Location location)
			{
				if(location!=null)
				{
					try
					{
						double latitude = location.getLatitude();//获得 经度
						double longitude = location.getLongitude();//获得 纬度
						double altitude = location.getAltitude();  //获得 海拔
						double speed = location.getSpeed();//获得速度
						double accuracy = location.getAccuracy();//获得精度 精确到m
						double degrees =location.getBearing();//获得方位角   东偏北n度
						double time=location.getTime();//获得卫星上的时间
						//卫星上的时间转换为当前时间
						SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						String timeNow=format.format(time);
						StringBuilder sb=new StringBuilder("当前GPS信息为:\n");
						sb.append("经度 :"+latitude+"\n");
						sb.append("纬度 :"+longitude+"\n");
						sb.append("海拔 :"+altitude+"\n");
						sb.append("速度 :"+speed+"\n");
						sb.append("精度m :"+accuracy+"\n");
						sb.append("方位角:"+degrees+"\n");
						sb.append("时间 :"+timeNow+"\n");
						EditText et=(EditText)findViewById(R.id.editText2);
						et.setText(sb.toString());
					}catch(Exception e)
					{
						e.printStackTrace();
					}}}
			@Override//Location Provider被禁用时更新
			public void onProviderDisabled(String provider){}
			@Override//Location Provider被启用时更新
			public void onProviderEnabled(String provider){}
			@Override//当Provider硬件状态变化时更新
			public void onStatusChanged(String provider, int status,Bundle extras){}
		};
		//卫星状态监听器
		GpsStatus.Listener statusListener = new GpsStatus.Listener()
		{
			@Override
			public void onGpsStatusChanged(int event)
			{//GPS状态变化时的回调,如卫星数
				//取当前卫星状态
				GpsStatus status = locationManager.getGpsStatus(null);
				//状态改变
				if(event == GpsStatus.GPS_EVENT_SATELLITE_STATUS)
				{
					//获得最大卫星数
					int maxSatellites = status.getMaxSatellites();
					//获得迭代器
					Iterator<GpsSatellite> it = status.getSatellites().iterator();
					//遍历所有的卫星
					StringBuilder sb=new StringBuilder();
					int count=0;
					while (it.hasNext())
					{
						GpsSatellite satellite = it.next();//下一个卫星
						sb.append("卫星"+(++count)+"\n");
						sb.append("信噪比:"+satellite.getSnr()+"\n");
						sb.append("方位角:"+satellite.getAzimuth()+"\n");
						sb.append("仰角:"+satellite.getElevation()+"\n");
						sb.append("============================\n");
					}
					sb.insert(0, "============================\n");
					sb.insert(0, "卫星数:"+count+"\n");
					sb.insert(0, "最大卫星数:"+maxSatellites+"\n");

					EditText et=(EditText)findViewById(R.id.editText1);
					et.setText(sb.toString());
				}
			}
		};
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,5000,0,ll); //添加位置变化监听器
		locationManager.addGpsStatusListener(statusListener);  //添加卫星状态监听器
	}

2018.9.20记

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑瞳丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值