private void showMap(double latitude, double longtitude, String address) { sendButton.setVisibility(View.GONE); GeoPoint point1 = new GeoPoint((int) (latitude * 1e6), (int) (longtitude * 1e6)); point1 = CoordinateConvert.fromGcjToBaidu(point1); mMapController.setCenter(point1); Drawable marker = this.getResources().getDrawable(R.drawable.icon_marka); // 为maker定义位置和边界 marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight()); mAddrOverlay = new ItemizedOverlay<OverlayItem>(marker, mMapView); GeoPoint point = new GeoPoint((int) (latitude * 1e6), (int) (longtitude * 1e6)); point = CoordinateConvert.fromGcjToBaidu(point); OverlayItem addrItem = new OverlayItem(point, "", address); mAddrOverlay.addItem(addrItem); mMapView.getOverlays().add(mAddrOverlay); mMapView.refresh(); }
public void clientInit() { // 初始化定位服务 mLocationClient = new LocationClient(getApplicationContext()); mLocationClient.setAK(accessKey); mLocationClient.registerLocationListener(myListener); LocationClientOption option = getLocationOption(); mLocationClient.setLocOption(option); mLocationData = new LocationData(); mLocationData.latitude = (double) (appData.lastLatitude) / 1E6; mLocationData.longitude = (double) (appData.lastLongitude) / 1E6; mLocationData.accuracy = appData.lastAccuracy; // 定位图层初始化 myLocationOverlay = new MyLocationOverlay(mMapView); // 设置定位数据 myLocationOverlay.setData(mLocationData); myLocationOverlay.setMarker(getResources().getDrawable(R.drawable.loading_point_medium)); // 添加定位图层 mMapView.getOverlays().add(myLocationOverlay); myLocationOverlay.enableCompass(); // 修改定位数据后刷新图层生效 mMapView.refresh(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DemoApplication app = (DemoApplication) this.getApplication(); if (app.mBMapManager == null) { app.mBMapManager = new BMapManager(this); app.mBMapManager.init(DemoApplication.strKey, new DemoApplication.MyGeneralListener()); } setContentView(R.layout.activity_itemizedoverlay); mMapView = (MapView) findViewById(R.id.bmapView); mMapController = mMapView.getController(); initMapView(); mMapView.getController().setZoom(13); mMapView.getController().enableClick(true); mMapView.setBuiltInZoomControls(true); testItemButton = (Button) findViewById(R.id.button1); removeItemButton = (Button) findViewById(R.id.button2); removeAllItemButton = (Button) findViewById(R.id.button3); Drawable marker = ItemizedOverlayDemo.this.getResources().getDrawable(R.drawable.icon_marka); mMapView.getOverlays().clear(); ov = new OverlayTest(marker, this, mMapView); mMapView.getOverlays().add(ov); OnClickListener clickListener = new OnClickListener() { public void onClick(View v) { testItemClick(); } }; OnClickListener removeListener = new OnClickListener() { public void onClick(View v) { testRemoveItemClick(); } }; OnClickListener removeAllListener = new OnClickListener() { public void onClick(View v) { testRemoveAllItemClick(); } }; testItemButton.setOnClickListener(clickListener); removeItemButton.setOnClickListener(removeListener); removeAllItemButton.setOnClickListener(removeAllListener); mMapListener = new MKMapViewListener() { @Override public void onMapMoveFinish() { // TODO Auto-generated method stub } @Override public void onClickMapPoi(MapPoi mapPoiInfo) { // TODO Auto-generated method stub String title = ""; if (mapPoiInfo != null) { title = mapPoiInfo.strText; Toast.makeText(ItemizedOverlayDemo.this, title, Toast.LENGTH_SHORT).show(); } } @Override public void onGetCurrentMap(Bitmap b) {} @Override public void onMapAnimationFinish() { // TODO Auto-generated method stub } }; mMapView.regMapViewListener(DemoApplication.getInstance().mBMapManager, mMapListener); res.add(getResources().getDrawable(R.drawable.icon_marka)); res.add(getResources().getDrawable(R.drawable.icon_markb)); res.add(getResources().getDrawable(R.drawable.icon_markc)); res.add(getResources().getDrawable(R.drawable.icon_markd)); res.add(getResources().getDrawable(R.drawable.icon_markf)); res.add(getResources().getDrawable(R.drawable.icon_markg)); res.add(getResources().getDrawable(R.drawable.icon_markh)); res.add(getResources().getDrawable(R.drawable.icon_marki)); // overlay 数量 int iSize = 9; double pi = 3.1415926; // overlay半径 int r = 50000; // 准备overlay 数据 for (int i = 0; i < iSize; i++) { int lat = (int) (cLat + r * Math.cos(2 * i * pi / iSize)); int lon = (int) (cLon + r * Math.sin(2 * i * pi / iSize)); OverlayItem item = new OverlayItem(new GeoPoint(lat, lon), "item" + i, "item" + i); item.setMarker(res.get(i % (res.size()))); mGeoList.add(item); } }
private void showMapWithLocationClient() { progressDialog = new ProgressDialog(this); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage("正在确定你的位置..."); progressDialog.setOnCancelListener( new OnCancelListener() { public void onCancel(DialogInterface arg0) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } Log.d("map cancel retrieve location"); finish(); } }); progressDialog.show(); mLocClient = new LocationClient(this); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开gps // option.setCoorType("bd09ll"); //设置坐标类型 // Johnson change to use gcj02 coordination. chinese national standard // so need to conver to bd09 everytime when draw on baidu map option.setCoorType("gcj02"); option.setScanSpan(30000); option.setAddrType("all"); mLocClient.setLocOption(option); Drawable marker = this.getResources().getDrawable(R.drawable.icon_marka); // 为maker定义位置和边界 marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight()); mAddrOverlay = new ItemizedOverlay<OverlayItem>(marker, mMapView); mMapView.getOverlays().add(mAddrOverlay); mMapListener = new MKMapViewListener() { @Override public void onMapMoveFinish() { // TODO Auto-generated method stub } @Override public void onClickMapPoi(MapPoi mapPoiInfo) { // TODO Auto-generated method stub String title = ""; if (mapPoiInfo != null) { title = mapPoiInfo.strText; Toast.makeText(BaiduMapActivity.this, title, Toast.LENGTH_SHORT).show(); } } @Override public void onGetCurrentMap(Bitmap b) { // TODO Auto-generated method stub } @Override public void onMapAnimationFinish() {} }; mMapView.regMapViewListener(mBMapManager, mMapListener); if (lastLocation != null) { GeoPoint point1 = new GeoPoint( (int) (lastLocation.getLatitude() * 1e6), (int) (lastLocation.getLongitude() * 1e6)); point1 = CoordinateConvert.fromGcjToBaidu(point1); mMapController.setCenter(point1); } mMapView.refresh(); mMapView.invalidate(); }