Esempio n. 1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_uisetting);

    mMapView = (MapView) findViewById(R.id.bmapView);
    mBaiduMap = mMapView.getMap();
    mUiSettings = mBaiduMap.getUiSettings();

    MapStatus ms = new MapStatus.Builder().overlook(-30).build();
    MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(ms);
    mBaiduMap.animateMapStatus(u, 1000);
  }
 @Override
 public void onReceiveLocation(BDLocation location) {
   // TODO Auto-generated method stub
   if (null != location
       && (location.getLocType() == BDLocation.TypeGpsLocation
           || location.getLocType() == BDLocation.TypeNetWorkLocation)) {
     System.out.println(
         "================>" + location.getLocType() + BDLocation.TypeOffLineLocation);
     StringBuffer sb = new StringBuffer(256);
     sb.append("time : ");
     sb.append(location.getTime());
     sb.append("\nlatitude : ");
     sb.append(location.getLatitude());
     sb.append("\nlontitude : ");
     sb.append(location.getLongitude());
     sb.append("\naddr : ");
     sb.append(location.getAddrStr());
     System.out.println(sb.toString());
     // 第一次去的的经纬度
     firstLocationLatitude = location.getLatitude();
     firstLocationLongitude = location.getLongitude();
     // 设置位置
     MyLocationData locData =
         new MyLocationData.Builder()
             .accuracy(location.getRadius())
             .direction(10)
             .latitude(location.getLatitude())
             .longitude(location.getLongitude())
             .build();
     baiduMap.setMyLocationData(locData);
     // 更新位置、比例系数、添加标志等状态
     LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
     markFirstLocation();
     markClickLocation(latLng);
     // 更新地图状态
     MapStatus mapStatus = new MapStatus.Builder().target(latLng).zoom(16).build();
     MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus);
     baiduMap.animateMapStatus(mapStatusUpdate);
     // 检索
     geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(latLng));
     // 停止定位
     client.stop();
   } else {
     // 定位失败
     showToast("定位失败,请检查网络,重新定位");
     SelectLocationActivity.this.setResult(RESULT_CANCELED);
     SelectLocationActivity.this.finish();
   }
 }
Esempio n. 3
0
  private void tipPlace(double lats, double longs) {
    if (i != 0) {
      // Log.e("iii", "i = "+i);
      marker.remove();
    }

    LatLng point = new LatLng(lats, longs);
    MapStatus mMapStatus =
        new MapStatus.Builder().target(point).zoom(CheezhiApplication.getZooms()).build();

    // mMapView.getMap().get

    MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
    mBaiduMap.setMapStatus(mMapStatusUpdate);
    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(point);
    mBaiduMap.animateMapStatus(u);

    BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_geo);

    OverlayOptions options =
        new MarkerOptions().position(point).icon(bitmap).zIndex(9).draggable(true);

    marker = (Marker) (mBaiduMap.addOverlay(options));
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    try {
      super.onCreate(savedInstanceState);
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.activity_hotel_location);
      ((MyApplication) getApplication()).addActivity(this);

      mMapView = (MapView) findViewById(R.id.bmapView);
      mBaidumap = mMapView.getMap();

      ((ImageButton) findViewById(R.id.back_imgbtn))
          .setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  finish();
                }
              });

      mLocationClient = new LocationClient(this.getApplicationContext());
      mLocationClient.registerLocationListener(new MyLocationListener());
      InitLocation();
      mLocationClient.start();
      mLocationClient.requestLocation();

      HotelDetail maphotel = null;
      Marker marker = null;
      BitmapDescriptor mIconMaker;
      OverlayOptions overlayOptions = null;
      Bundle bundle = this.getIntent().getExtras();
      if (bundle != null)
        if (bundle.containsKey("hotel"))
          try {
            maphotel = JSONHelper.parseObject(bundle.getString("hotel"), HotelDetail.class);
          } catch (Exception e) {
            e.printStackTrace();
          }
      LatLng latLng =
          new LatLng(Double.parseDouble(maphotel.getY()), Double.parseDouble(maphotel.getX()));
      hotelY = Double.parseDouble(maphotel.getY());
      hotelX = Double.parseDouble(maphotel.getX());
      View view = getMapView(maphotel.getHotelname(), maphotel.getMin_price());
      mIconMaker = BitmapDescriptorFactory.fromView(view);
      // 图标
      overlayOptions = new MarkerOptions().position(latLng).icon(mIconMaker).zIndex(5);
      marker = (Marker) (mBaidumap.addOverlay(overlayOptions));

      // 设定中心点坐标
      MapStatus mMapStatus = new MapStatus.Builder().target(latLng).zoom(16).build();
      // 定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
      MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
      mBaidumap.setMapStatus(mMapStatusUpdate);

      mBaidumap.setOnMarkerClickListener(
          new OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(final Marker marker) {
              // startNavi();
              return true;
            }
          });

      ((ImageButton) findViewById(R.id.navi_imgbtn))
          .setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                  startNavi();
                }
              });
    } catch (Exception e) {
      e.printStackTrace();
    }
  }