显示地图的基本定位,刚进入地图的定位点
大连位置
//获取地图的初始位置
private void setUserMapCenter() {
double lat = 38.766831;
double lon = 122.075787;
LatLng cenpt = new LatLng(lat, lon);
aMap = mapView.getMap();
aMap.moveCamera(CameraUpdateFactory.changeLatLng(cenpt));
}
//设置地图上的自定义图标
//小船信息
Gson gson = new Gson();
mapBean = gson.fromJson(json, MapBean.class);
List<MapBean.DetailsBean> list = mapBean.getDetails();
for (int i = 0; i < list.size(); i++) {
final float lat = list.get(i).getLat();
final float lon = list.get(i).getLon();
int drawers=R.drawable.s;
int drawerg=R.drawable.g;
if (i%2==0){
loadboat(lat,lon,drawers);
}else{
loadboat(lat,lon,drawerg);
}
marker.setObject(list.get(i));
marker.setFlat(true);
marker.setPerspective(true);
//设置自定义图标的方法
//在地图上显示船舶的位置
public void loadboat(float lat,float lon,int drawer){
LatLng latLng = new LatLng(lat, lon);
marker = aMap.addMarker(new MarkerOptions().
position(latLng).
title("").
icon(BitmapDescriptorFactory
.fromBitmap(BitmapFactory
.decodeResource(getResources(),
drawer))));
}
点击图标,弹出图标的具体信息和自定义窗口
//弹出窗口
aMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
return true;
}
});
//点击其它区域隐藏窗口
aMap.setOnMapClickListener(new AMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
if (marker!=null){
marker.hideInfoWindow();
}
}
});
//设置弹出窗口
private void setInfowindow() {
aMap.setInfoWindowAdapter(new AMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
View view=View.inflate(MapActivity.this,R.layout.boat_popwindow,null);
MapBean.DetailsBean bean = (MapBean.DetailsBean) marker.getObject();
initPopView(view,bean);
return view;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
});
}
//自定义窗口信息
//设置窗口数据
private void initPopView(View view, final MapBean.DetailsBean bean) {
pop_name= (TextView) view.findViewById(R.id.pop_name);
pop_mmsi= (TextView) view.findViewById(R.id.pop_mmsi);
pop_style= (TextView) view.findViewById(R.id.pop_style);
pop_time= (TextView) view.findViewById(R.id.pop_time);
pop_plan= (ImageView) view.findViewById(R.id.pop_plan);
pop_collect= (ImageView) view.findViewById(R.id.pop_collect);
initDataPlan(bean.getLat(),bean.getLon());
//赋值
pop_name.setText("船名:"+bean.getName()+"\t");
pop_mmsi.setText("MMSI:"+bean.getMmsi()+"\t");
if (bean.getNav_status().equals("0")){
pop_style.setText("航行状态:"+"锚泊"+"\t");
}else{
pop_style.setText("航行状态:"+"航行中"+"\t");
}
//String date = strToDateLong(bean.getTime());
pop_time.setText("最后时间:"+bean.getTime()+"\t");
pop_collect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MapActivity.this, ShipMsgActivity.class);
intent.putExtra("MMSI",bean.getMmsi());
startActivity(intent);
}
});
pop_plan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//设置图标的缩放大小 aMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(Double.parseDouble(String.valueOf(bean.getLat())),Double.parseDouble(String.valueOf(bean.getLon()))),//新的中心点坐标
15, //新的缩放级别
0, //俯仰角0°~45°(垂直与地图时为0)
0//偏航角 0~360° (正北方为0)
)));
polyline = aMap.addPolyline(new PolylineOptions().
addAll(latLngs).width(1).color(Color.BLUE));
}
});
}
//设置自定义图标的轨迹方法
List<LatLng> latLngs = new ArrayList<LatLng>();
latLngs.add(new LatLng(39.999391,116.135972));
latLngs.add(new LatLng(39.898323,116.057694));
latLngs.add(new LatLng(39.900430,116.265061));
latLngs.add(new LatLng(39.955192,116.140092));
polyline =AMap.addPolyline(new PolylineOptions().
addAll(latLngs)..width(10).color(Color.argb(255, 1, 1, 1)));