目錄
一、定位偏差問題
1.問題描述
第一週完成了百度地圖的基本定位顯示,
同時發現定位偏差在一千米以上。
2.解決方法
(1)設置定位的最高精度:
option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
查看具體經緯度信息輸出:
import android.util.Log;
protected static final String TAG="ReceiveLoc";
Log.i(TAG, " latitude: " + latitude);
Log.i(TAG," longitude: " + longitude );
查看logcat:
保持原來的偏差:
(2)百度地圖的座標與真實經緯度是不同的,國際經緯度座標標準爲WGS-84,國內必須至少使用國測局制定的GCJ-02,對地理位置進行首次加密。百度座標在此基礎上,進行了BD-09二次加密措施,百度對外接口的座標系並不是GPS採集的真實經緯度,需要通過座標轉換接口進行轉換。
option.setCoorType("bd09ll");// 返回的定位結果是百度經緯度
二、Marker
1.功能描述
在地圖上添加一個樹莓派的定位標記紅點。
2.具體實現
使用覆蓋物Marker在地圖上進行標記。
private void setMarker(double lat,double lon) {
//定義Maker座標點
LatLng point = new LatLng(lat,lon);
//構建Marker圖標
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher_round);
//構建MarkerOption,用於在地圖上添加Marker
OverlayOptions option = new MarkerOptions().position(point).icon(bitmap);
//在地圖上添加Marker,並顯示
baiduMap.addOverlay(option);
}
三、InfoWindow
1.功能描述
實現點擊Marker(樹莓派標記紅點),通過彈出覆蓋物的信息窗口,顯示更多的信息。
2.關鍵函數
InfoWindow mInfoWindow = new InfoWindow
(BitmapDescriptor bd, LatLng postion,int yOffset, InfoWindow.OnInfoWindowClickListener);
參數:
bd - InfoWindow 展示的bitmap
position - InfoWindow 顯示的地理位置
yOffset - InfoWindow Y 軸偏移量
listener - InfoWindow 點擊監聽者
3.參數實現
mInfoWindow = new InfoWindow(bttmap, llInfo, -47, infoWindowClicklistener);
(1)展示的bttmap
//生成一個TextView用戶在地圖中顯示InfoWindow
TextView location = new TextView(getApplicationContext())
......
//轉換爲Bitmap對象
BitmapDescriptor bttmap = BitmapDescriptorFactory.fromView(location);
(2)顯示的地理位置llInfo
//將marker所在的經緯度的信息轉化成屏幕上的座標
final LatLng llInfo = baiduMap.getProjection().fromScreenLocation(baiduMap.getProjection().toScreenLocation(marker.getPosition();));
(3)InfoWindow 點擊監聽者
//爲彈出的InfoWindow添加點擊事件
OnInfoWindowClickListener infoWindowClicklistener = new OnInfoWindowClickListener() ;
//爲監聽添加事件
public void onInfoWindowClick();
//隱藏InfoWindow
baiduMap.hideInfoWindow();
//顯示InfoWindow
baiduMap.showInfoWindow(mInfoWindow);
四、跳轉界面的方法
1.實現步驟
1.MainActivity的點擊事件中加入Intent:
Intent(意圖)主要是解決Android應用的各項組件之間的通訊。
Intent負責對應用中一次操作的動作、動作涉及數據、附加數據進行描述,Android則根據此Intent的描述,負責找到對應的組件,將 Intent傳遞給調用的組件,並完成組件的調用。
Intent intent = new Intent();
想要啓動的目標活動:SecondActivity.class
intent.setClass(MainActivity.this,SecondActivity.class);
啓動目標活動:
startActivity(intent);
2.註冊活動(Android Studio會自動幫我們完成)
<activity android:name=".SecondActivity">
3.secondActivity中添加:
設置頁面的內容視圖:
setContentView(R.layout.activity_second);
4.視圖佈局
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="second_activitity \n details for weather"/>
2.結果截圖
此時點擊infowindow,
會跳轉到第二個頁面。