显示地图

显示地图的全部代码
-----------------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);
}
});
--------------------- 

posted @ 2019-08-01 19:10  水至清明  阅读(189)  评论(0编辑  收藏  举报