现在的位置: 首页 > 综合 > 正文

2013年7月14日 20:50:54

2013年08月10日 ⁄ 综合 ⁄ 共 4484字 ⁄ 字号 评论关闭

0714

android的学习接近尾声?
然后是总结和复习,利用思维导图把我们android所有的东西总结下来,理出一条线
组件,API,等。3天,下周三,IMindMap,
--------------
通过Web Service进行网络编程,是在互联网上可调其他的远程,跟语言、平台无关,
传输协议【SOAP】,Simple Object Access Protocol简单对象访问协议,请求的是HTTP,发送和接收的是SOAP协议,
Web服务器描述语言【WSDL】,Web Service Description Language,XML文件(⊙o⊙)

城市天气,服务,电子书上。
---------------
十六章Android中的GPS应用
copy【TestLocationActivity】代码

--------【记住导自己的过程】,有道笔记是什么?云储存?
明天,传感器

 个很怀念的名词呢~

/**
 * 测试location界面
 * 
 * @author Administrator
 * 
 */
public class TestLocationActivity extends Activity implements OnClickListener, LocationListener {
	private TextView showProviderView;
	private LocationManager locationManager;
	private Location location;
	private Button getProviderBtn,addProviderBtn;
	private TextView showEditText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_test_location_);
		getProviderBtn = (Button) findViewById(R.id.test_loaction_main_btn_getprovider);
		addProviderBtn=(Button) findViewById(R.id.test_loaction_main_btn_addPoint);
		showProviderView = (TextView) findViewById(R.id.test_loaction_main_tv_showlocation);
		showEditText=(TextView) findViewById(R.id.test_loaction_main_tv_show);
		// 获取定位管理器
		locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

		getProviderBtn.setOnClickListener(this);
		addProviderBtn.setOnClickListener(this);
//		//注册跟踪位置的监听器
//		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 1, new LocationListener() {
//			public void onStatusChanged(String provider, int status, Bundle extras) {
//			}
//			//当provider能够使用的时候调用
//			public void onProviderEnabled(String provider) {
//				getLocationInfo(locationManager.getLastKnownLocation(provider));
//			}
//			public void onProviderDisabled(String provider) {
//			}
//			//当位置发生改变时调用
//			public void onLocationChanged(Location location) {
//				getLocationInfo(location);
//			}
//		});
		
	}

	@Override
	protected void onResume() {
		super.onResume();
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 1, this);
	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		locationManager.removeUpdates(this);
	}
	
	@Override
	public void onClick(View v) {
		if (v == getProviderBtn) {
			// 获取所有的定位方式
			List providerList = locationManager.getAllProviders();
			StringBuffer sb = new StringBuffer();
			sb.append("获取所有的定位方式:" + providerList + "\n");

			// 获取可用的定位方式
			List enableProviderList = locationManager.getProviders(true);
			sb.append("获取可用的定位方式:" + enableProviderList + "\n");

			// 根据条件或定位方式
			Criteria criteria = new Criteria();
			criteria.setCostAllowed(true);// 获取免费的定位方式
			criteria.setAltitudeRequired(true);// 获取能够提供高度的定位方式
			criteria.setBearingRequired(true);// 获取能够提供方向的定位方式
			List criteriaProviderList = locationManager.getProviders(criteria,
					true);
			sb.append("获取根据条件过滤的定位方式:" + criteriaProviderList + "\n");

			// 通过获取的定位方式来得到定位信息
			if (criteriaProviderList.contains(LocationManager.GPS_PROVIDER)) {
				location = locationManager
						.getLastKnownLocation(LocationManager.GPS_PROVIDER);
			} else if (criteriaProviderList
					.contains(LocationManager.NETWORK_PROVIDER)) {
				location = locationManager
						.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
			}
			String locationStr = getLocationInfo(location);
			sb.append("位置信息:\n" + locationStr);
		}
		if (v==addProviderBtn) {
			double latitude=40;//纬度
			double longitude=50;//经度
			float radius=10000;//半径10km
			long expiration=-1l;//警告的频率
			Intent intent =new Intent(this,AlertReceiver.class);//"com.lovo.an0714.location.alert"
			PendingIntent pi=PendingIntent.getBroadcast(this, 0, intent, 0);
			locationManager.addProximityAlert(latitude, longitude, radius, expiration, pi);
	
			Toast.makeText(this, "添加临近点成功", 3000).show();
		}
	}
	/**
	 * 获取定位信息
	 * 
	 * @param location
	 */
	private String getLocationInfo(Location location2) {
		StringBuffer sb = new StringBuffer();
		if (location != null) {
			// 得到精度
			sb.append("经度:" + location.getLongitude());
			sb.append("纬度:" + location.getLatitude());
			sb.append("高度:" + location.getAltitude());
			sb.append("方向:" + location.getBearing());
			sb.append("速度:" + location.getSpeed());
			sb.append("精确度:" + location.getAccuracy());

//			showEditText.setText(sb.toString());
		} else {
//			sb.append("");// 没有获取则清空
			sb.append("没有获取位置信息");
//			showEditText.setText(sb.toString());
		}
		showProviderView.setText(sb);
		return sb.toString();
	}

	@Override
	public void onLocationChanged(Location location) {
		this.location = location;
		Log.i("onLocationChanged", location+"");
	}
	@Override
	public void onProviderDisabled(String provider) {
	}
	@Override
	public void onProviderEnabled(String provider) {
		if(location == null){
			location = locationManager.getLastKnownLocation(provider);
		}
	}
	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
	}

}

好多服务,看起来很方便呢,关键是要多去用,比如若定位自己手机,或亲友的~做什么圣光和暗牧的事就能多个保障了哈哈~

小平板重力感应坏了,我去啊,这才几天...泪奔..别说我躺着看横屏很方便了.但是这是bug啊bug懂么亲?该治!!



妈妈昨天在吐槽我的恋爱问题...额..

抱歉!评论已关闭.