編輯:關於Android編程
/**
* 初始化定位
*/
private void initMyLocation() {
// 地圖初始化
mBaiduMap = mMapView.getMap();
MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f);
mBaiduMap.setMapStatus(msu);
// 開啟定位圖層
//mBaiduMap.setMyLocationEnabled(true);
// 定位初始化
mLocClient = new LocationClient(this);
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// 打開gps
option.setCoorType(bd09ll); // 設置坐標類型
option.setScanSpan(1000);//設置發起定位請求的間隔時間為1000ms
option.setIsNeedAddress(true);//返回的定位結果包含地址信息
option.setNeedDeviceDirect(true);//返回的定位結果包含手機機頭的方向
mLocClient.setLocOption(option);//設置定位參數
//mLocClient.start();
}
/**
* 定位的監聽器
*
* @author TanZuAi
*/
public class MyOrientationListener implements SensorEventListener {
private Context context;
private SensorManager sensorManager;
private Sensor sensor;
private float lastX;
private OnOrientationListener onOrientationListener;
public MyOrientationListener(Context context) {
this.context = context;
}
// 開始
public void start() {
// 獲得傳感器管理器
sensorManager = (SensorManager) context
.getSystemService(Context.SENSOR_SERVICE);
if (sensorManager != null) {
// 獲得方向傳感器
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
}
// 注冊
if (sensor != null) {// SensorManager.SENSOR_DELAY_UI
sensorManager.registerListener(this, sensor,
SensorManager.SENSOR_DELAY_UI);
}
}
// 停止檢測
public void stop() {
sensorManager.unregisterListener(this);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
public void onSensorChanged(SensorEvent event) {
// 接受方向感應器的類型
if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {
// 這裡我們可以得到數據,然後根據需要來處理
float x = event.values[SensorManager.DATA_X];
if (Math.abs(x - lastX) > 1.0) {
onOrientationListener.onOrientationChanged(x);
}
lastX = x;
}
}
public void setOnOrientationListener(
OnOrientationListener onOrientationListener) {
this.onOrientationListener = onOrientationListener;
}
public interface OnOrientationListener {
void onOrientationChanged(float x);
}
}
@Override
protected void onStart() {
// 開啟圖層定位
mBaiduMap.setMyLocationEnabled(true);
if (!mLocClient.isStarted())
{
mLocClient.start();
}
// 開啟方向傳感器
myOrientationListener.start();
super.onStart();
}
@Override
protected void onStop()
{
// 關閉圖層定位
mBaiduMap.setMyLocationEnabled(false);
mLocClient.stop();
// 關閉方向傳感器
myOrientationListener.stop();
super.onStop();
}
/**
* 初始化方向傳感器
*/
private void initOritationListener()
{
myOrientationListener = new MyOrientationListener(
getApplicationContext());
myOrientationListener
.setOnOrientationListener(new OnOrientationListener()
{
@Override
public void onOrientationChanged(float x)
{
mXDirection = (int) x;
// 構造定位數據
MyLocationData locData = new MyLocationData.Builder()
.accuracy(mCurrentAccracy)
// 此處設置開發者獲取到的方向信息,順時針0-360
.direction(mXDirection)
.latitude(mCurrentLantitude)
.longitude(mCurrentLongitude).build();
// 設置定位數據
mBaiduMap.setMyLocationData(locData);
// 設置自定義圖標
mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.navi_map_gps_locked);
mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(
mCurrentMode, true, mCurrentMarker));
}
});
}
學習Android之第五個小程序騰訊微博樣式(Listview的使用)
效果圖: public SimpleAdapter(Context context, List extends Map data, int resou
安卓APK瘦身
之前打包的時候直接就用eclipse或者android studio直接生成簽名文件,並沒有關心大小問題,最近有人問我有沒有對APK進行瘦身,對這方面內容一致沒有關注過,
Android四大組件之Service初涉
(一)概述好的,我們在前三節中對Android中的Activity進行了研究學習,相信大家獲益良多吧! 本節開始我們繼續來學習Android中的第二個組件:Service
Android開發之使用Web Service進行網絡編程
使用Web Service進行網絡編程 Android應用通常都是運行在手機平台上,手機系統的硬件資源是有限的,不管是存儲能力還是計算能力都有限,在Android系統上開