Ejemplo n.º 1
0
  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();
  }
Ejemplo n.º 2
0
    @Override
    public void onReceiveLocation(BDLocation location) {
      if (location == null) {
        return;
      }
      Log.d("map On location change received:" + location);
      Log.d("map addr:" + location.getAddrStr());
      sendButton.setEnabled(true);
      if (progressDialog != null) {
        progressDialog.dismiss();
      }

      if (lastLocation != null) {
        if (lastLocation.getLatitude() == location.getLatitude()
            && lastLocation.getLongitude() == location.getLongitude()) {
          Log.d("map same location, skip refresh");
          // mMapView.refresh(); //need this refresh?
          return;
        }
      }

      lastLocation = location;

      GeoPoint gcj02Point =
          new GeoPoint((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6));
      EMLog.d(TAG, "GCJ-02 loc:" + gcj02Point);
      GeoPoint point = CoordinateConvert.fromGcjToBaidu(gcj02Point);
      EMLog.d(TAG, "converted BD-09 loc:" + point);

      // GeoPoint p1 = gcjToBaidu(location.getLatitude(),
      // location.getLongitude());
      // System.err.println("johnson change to baidu:" + p1);
      // GeoPoint p2 = baiduToGcj(location.getLatitude(),
      // location.getLongitude());
      // System.err.println("johnson change to gcj:" + p2);

      OverlayItem addrItem = new OverlayItem(point, "title", location.getAddrStr());
      mAddrOverlay.removeAll();
      mAddrOverlay.addItem(addrItem);
      mMapView.getController().setZoom(17);
      mMapView.refresh();
      mMapController.animateTo(point);
    }
Ejemplo n.º 3
0
  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();
  }