/** 添加辅助marker LatLng 要显示的位置 View marker的图标 */ private String drawAssistMarkers(LatLng latlng, View view) { Marker marker = aMap.addMarker( new MarkerOptions() .position(latlng) // 设置当前MarkerOptions 对象的经纬度。 .icon(BitmapDescriptorFactory.fromView(view)) .draggable(true) // 设标记是否可被拖动 ); marker.showInfoWindow(); // 设置默认显示一个infowinfow return marker.getId(); }
/** 对marker标注点点击响应事件 */ @Override public boolean onMarkerClick(Marker marker) { // TODO Auto-generated method stub /// 如果点击当前点,则不响应. /// 如果是其他的点,则跳转到该点的详细界面 if (marker.getId().equals(marker_id)) { ToastUtil.show(this, "你点击的是主marker " + marker.getId()); onMarkerClick(); } else { ToastUtil.show(this, "你点击的是辅marker " + marker.getId()); onAssistMarkerClick(marker.getId()); } return false; }
/** 绘制系统默认的1种marker 背景图片 LatLng 要显示的坐标位置 title Marker标题的内容 snippet Marker标题snippet的内容 */ private void drawMainMarkers(LatLng latlng, String title, String snippet) { Marker marker = aMap.addMarker( new MarkerOptions() .position(latlng) // 设置当前MarkerOptions 对象的经纬度。 .title(title) // 设置 Marker 的标题 .snippet(snippet) // 设置 Marker 上的 snippet .icon( BitmapDescriptorFactory.fromResource( R.drawable.main_map_position)) // 设置marker 图标 .draggable(true) // 设标记是否可被拖动 ); marker_id = marker.getId(); marker.showInfoWindow(); // 设置默认显示一个infowinfow }
/** 监听点击infowindow窗口事件回调 */ @Override public void onInfoWindowClick(Marker marker) { // TODO Auto-generated method stub /// 此处跳转到列表框界面/// ToastUtil.show(this, "你点击了infoWindow窗口" + marker.getTitle()); // 调用列表Activity }
@Override public void onCameraChangeFinish(CameraPosition cameraPosition) { locationX = cameraPosition.target.latitude; locationY = cameraPosition.target.longitude; latLng = new LatLng(locationX, locationY); latLonPoint = AMapUtil.convertToLatLonPoint(latLng); getAddress(latLonPoint); doSearchQuery(latLonPoint); regeoMarker.setPosition(latLng); }
/** 监听自定义infowindow窗口的infowindow事件回调 */ @Override public View getInfoWindow(Marker marker) { // TODO Auto-generated method stub View infoWindow; if (marker.getId().equals(marker_id)) infoWindow = getLayoutInflater().inflate(R.layout.main_info_window, null); else infoWindow = getLayoutInflater().inflate(R.layout.main_info_window_2, null); render(marker, infoWindow); return infoWindow; }
/** 监听自定义infowindow窗口的infocontents事件回调 */ @Override public View getInfoContents(Marker marker) { // TODO Auto-generated method stub View infoContent; if (marker.getId().equals(marker_id)) infoContent = getLayoutInflater().inflate(R.layout.main_info_contents, null); else infoContent = getLayoutInflater().inflate(R.layout.main_info_contents, null); render(marker, infoContent); return infoContent; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.issue_gaodeditu); Intent intent = getIntent(); isChooseAddress = intent.getBooleanExtra("isChooseAddress", false); mapView = (MapView) findViewById(R.id.map); mapView.onCreate(savedInstanceState); // 此方法必须重写 sharedPreferences = getSharedPreferences(Constants.LOGIN_PREFERENCE, Context.MODE_PRIVATE); locationCity = sharedPreferences.getString("LocationCity", "北京"); getActionBar().setTitle(locationCity); getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayShowHomeEnabled(true); init(); String LocationXStr = sharedPreferences.getString("LocationX", ""); String locationYStr = sharedPreferences.getString("LocationY", ""); if (isChooseAddress) { locationX = intent.getDoubleExtra("LocationX", 0.0); locationY = intent.getDoubleExtra("LocationY", 0.0); locationCity = intent.getStringExtra("LocationCityName"); latLng = new LatLng(locationX, locationY); latLonPoint = AMapUtil.convertToLatLonPoint(latLng); aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18)); // 设置当前地图显示为北京市恭王府 getAddress(latLonPoint); doSearchQuery(latLonPoint); regeoMarker.setPosition(latLng); } else { if (!TextUtils.isEmpty(LocationXStr) && !TextUtils.isEmpty(locationYStr)) { locationX = Double.parseDouble(LocationXStr); locationY = Double.parseDouble(locationYStr); latLng = new LatLng(locationX, locationY); latLonPoint = AMapUtil.convertToLatLonPoint(latLng); aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18)); getAddress(latLonPoint); doSearchQuery(latLonPoint); regeoMarker.setPosition(latLng); } } }
/** 自定义infowinfow窗口, 设置title 和 snippet 的内容 */ public void render(Marker marker, View view) { if (!marker.getId().equals(marker_id)) return; String title = marker.getTitle(); TextView titleUi = ((TextView) view.findViewById(R.id.main_infowindow_textview_title_id)); if (title != null) { SpannableString titleText = new SpannableString(title); titleUi.setText(titleText); Log.e("title", titleText.toString()); } else { titleUi.setText(""); } if (marker.getId().equals(marker_id)) { String snippet = marker.getSnippet(); TextView snippetUi = ((TextView) view.findViewById(R.id.main_infowindow_textview_snippet_id)); if (snippet != null) { SpannableString snippetText = new SpannableString(snippet); snippetUi.setText(snippetText); Log.e("snippet", snippetText.toString()); } else { titleUi.setText(""); } } }