显示地图
顯示地圖的全部代碼
-----------------xml中的代碼
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f8f8ff"
android:orientation="vertical" >
<com.baidu.mapapi.map.TextureMapView
android:id="@+id/RegionalCoordinatesbRegionMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" >
</com.baidu.mapapi.map.TextureMapView>
</LinearLayout>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class類中的代碼,其中包含多位置標點 點擊標點顯示提示文本框并在點擊文本框時執行對應的點擊事件
public class RegionalCoordinates extends Activity{
private BaiduMap baiduMap;
private TextureMapView mMapView;
private MapStatusUpdate msu ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.regional_coordinates);
mMapView = (TextureMapView) findViewById(R.id.RegionalCoordinatesbRegionMap);
init();
}
private void init() {
// TODO Auto-generated method stub
baiduMap = mMapView.getMap();
baiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
baiduMap.setTrafficEnabled(true);
// 設置初始加載位置
msu = MapStatusUpdateFactory.newLatLngZoom(new LatLng(24.800427,118.599943),13);
baiduMap.setMapStatus(msu);
List<OverlayOptions> options = new ArrayList<OverlayOptions>();
for (Map<String, Object> map : DatasStatistics.getRegionMap()) {
Map<String, Object> obj= (Map<String, Object>) map.get("datastatistics");
//構建Marker圖標
BitmapDescriptor bitmap;
//用來構造InfoWindow
if(obj==null||(Double)obj.get("blockagedegree")>20){
bitmap = BitmapDescriptorFactory
.fromResource(R.drawable.exception);
}else{
bitmap = BitmapDescriptorFactory
.fromResource(R.drawable.yes);
}
//定義Maker坐標點
LatLng point1 = new LatLng((Double) map.get("latitude"), (Double) map.get("longitude"));
//構建MarkerOption,用于在地圖上添加Marker
OverlayOptions option1 = new MarkerOptions()
.position(point1)
.icon(bitmap);
options.add(option1);
}
baiduMap.addOverlays(options);
//獲取地圖標記點擊事件
baiduMap.setOnMarkerClickListener(new OnMarkerClickListener() {
//加載標點上方文本點擊事件
InfoWindow.OnInfoWindowClickListener listener = new InfoWindow.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick() {
Intent i = new Intent(RegionalCoordinates.this, SingleDetails.class);
startActivity(i);
overridePendingTransition(R.anim.fade_out,R.anim.fade_in);
}
};
//加載標點點擊事件
@Override
public boolean onMarkerClick(Marker mak) {
//設置文本標題
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.tips);
LatLng latLng =mak.getPosition();
//設置參數為了得到詳情利用經緯度
DatasStatistics.setLatLng(latLng);
//傳值顯示
InfoWindow mInfoWindow = new InfoWindow(bitmap, latLng, -30, listener);
baiduMap.showInfoWindow(mInfoWindow);
return false;
}
});
//在地圖上添加Marker,并顯示
}
@Override
protected void onDestroy() {
super.onDestroy();
//在activity執行onDestroy時執行mMapView.onDestroy(),實現地圖生命周期管理
mMapView.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
//在activity執行onResume時執行mMapView. onResume (),實現地圖生命周期管理
mMapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
//在activity執行onPause時執行mMapView. onPause (),實現地圖生命周期管理
mMapView.onPause();
}
@Override
public void onBackPressed() {
Intent i = new Intent(RegionalCoordinates.this, TableDetails.class);
startActivity(i);
overridePendingTransition(R.anim.fade_out,R.anim.fade_in);
}
private long logOut =0;
private long lastClickTime=0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
最終顯示效果
,利用經緯度對通過url跳轉百度地圖
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Uri uri = Uri.parse("http://api.map.baidu.com/geocoder?location="+
DatasStatistics.getLatLng().latitude+","+DatasStatistics.getLatLng().longitude+"&coord_type=bd09ll&output=html&src=webapp.baidu.openAPIdemo");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
---------------------?
轉載于:https://www.cnblogs.com/hyhy904/p/11284669.html
總結
- 上一篇: 基于roslyn的动态编译库Natash
- 下一篇: TextTree - 文本资料收集轻量级