private void initBaiduMap() {
    mapView = (MapView) findViewById(R.id.bmapView);
    baiduMap = mapView.getMap();
    baiduMap.setMaxAndMinZoomLevel(18, 13);
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
    iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
    receiver = new BaiduReceiver();
    registerReceiver(receiver, iFilter);

    geoCoder = GeoCoder.newInstance();
    geoCoder.setOnGetGeoCodeResultListener(this);

    Intent intent = getIntent();
    intentType = intent.getStringExtra(TYPE);
    initActionBar(R.string.chat_position);
    if (intentType.equals(TYPE_SELECT)) {
      // 选择发送位置
      // 开启定位图层
      baiduMap.setMyLocationEnabled(true);
      baiduMap.setMyLocationConfigeration(
          new MyLocationConfigeration(MyLocationConfigeration.LocationMode.NORMAL, true, null));
      // 定位初始化
      locClient = new LocationClient(this);
      locClient.registerLocationListener(myListener);
      LocationClientOption option = new LocationClientOption();
      option.setProdName("avosim");
      option.setOpenGps(true);
      option.setCoorType("bd09ll");
      option.setScanSpan(1000);
      option.setOpenGps(true);
      option.setIsNeedAddress(true);
      option.setIgnoreKillProcess(true);
      locClient.setLocOption(option);
      locClient.start();
      if (locClient != null && locClient.isStarted()) {
        locClient.requestLocation();
      }
      if (lastLocation != null) {
        // 显示在地图上
        LatLng ll = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        baiduMap.animateMapStatus(u);
      }
    } else {
      Bundle b = intent.getExtras();
      LatLng latlng = new LatLng(b.getDouble(LATITUDE), b.getDouble(LONGITUDE)); // 维度在前,经度在后
      baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(latlng));
      OverlayOptions ooA = new MarkerOptions().position(latlng).icon(descriptor).zIndex(9);
      baiduMap.addOverlay(ooA);
    }
  }
  /**
   * 把一个坐标点显示在地图上面.
   *
   * @param mMapView
   * @param point
   * @param image 默认图片资源id
   */
  public void showOnePoint(final BaiduMap mBaiduMap, final MyPoint point, int image) {
    mBaiduMap.clear();

    LatLng llA = new LatLng(point.getLat(), point.getLng());
    BitmapDescriptor bdA = BitmapDescriptorFactory.fromResource(R.drawable.icon_geo);

    OverlayOptions ooA = new MarkerOptions().position(llA).icon(bdA).zIndex(9).draggable(true);
    final Marker mMarkerA = (Marker) (mBaiduMap.addOverlay(ooA));

    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(llA);
    mBaiduMap.setMapStatus(u);
    mBaiduMap.setOnMarkerClickListener(
        new OnMarkerClickListener() {
          public boolean onMarkerClick(final Marker marker) {
            Button button = new Button(context);
            button.setBackgroundResource(R.drawable.popup);
            OnInfoWindowClickListener listener = null;
            if (marker == mMarkerA) {
              button.setText(point.getName());
              listener =
                  new OnInfoWindowClickListener() {
                    public void onInfoWindowClick() {
                      mBaiduMap.hideInfoWindow();
                    }
                  };
              LatLng ll = marker.getPosition();
              InfoWindow mInfoWindow =
                  new InfoWindow(BitmapDescriptorFactory.fromView(button), ll, -47, listener);
              mBaiduMap.showInfoWindow(mInfoWindow);
            }
            return true;
          }
        });
  }
    @Override
    public void onReceiveLocation(BDLocation location) {
      // map view 销毁后不在处理新接收的位置
      if (location == null || mMapView == null) return;
      MyLocationData locData =
          new MyLocationData.Builder()
              .accuracy(location.getRadius())
              // 此处设置开发者获取到的方向信息,顺时针0-360
              .direction(100)
              .latitude(location.getLatitude())
              .longitude(location.getLongitude())
              .build();
      mBaiduMap.setMyLocationData(locData);
      double Lo = location.getLongitude();
      double La = location.getLatitude();
      userLoc.setLongitude(Lo); // 保存用户当前位置
      userLoc.setLatitude(La);
      System.out.println("起点");
      System.out.println("经度:" + userLoc.getLongitude());
      System.out.println("纬度:" + userLoc.getLatitude());

      if (isFirstLoc) {
        isFirstLoc = false;
        LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        mBaiduMap.animateMapStatus(u);
      }
    }
Example #4
0
    @Override
    public void onReceiveLocation(BDLocation location) {
      // map view 销毁后不在处理新接收的位置
      if (location == null || mMapView == null) return;
      // 获取当前位置坐标点
      StringBuffer sb = new StringBuffer(256);
      sb.append("\nlatitude : ");
      sb.append(location.getLatitude());
      x2 = location.getLatitude();
      y2 = location.getLongitude();
      sb.append("\nlontitude : ");
      sb.append(location.getLongitude());
      Toast.makeText(MyApplication.getContext(), "目前定位的坐标为:" + sb.toString(), Toast.LENGTH_LONG)
          .show();

      MyLocationData locData =
          new MyLocationData.Builder()
              .accuracy(location.getRadius())
              // 此处设置开发者获取到的方向信息,顺时针0-360
              .direction(100)
              .latitude(location.getLatitude())
              .longitude(location.getLongitude())
              .build();
      mBaiduMap.setMyLocationData(locData);
      if (isFirstLoc) {
        isFirstLoc = false;
        LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        mBaiduMap.animateMapStatus(u);
      }
    }
Example #5
0
  /** 设置当前位置,如果是第一次则动画移动到当前位置 */
  private void setMyLocOnMap() {

    MyLocationData.Builder builder =
        new MyLocationData.Builder()
            .latitude(cLoc.getLatitude())
            .longitude(cLoc.getLongitude())
            .accuracy(cLoc.getRadius())
            .direction(mOrientation);
    baiduMap.setMyLocationData(builder.build());

    if (currentIcon == null) {
      currentIcon = BitmapDescriptorFactory.fromResource(R.mipmap.main_icon_nav);
    }

    baiduMap.setMyLocationConfigeration(
        new MyLocationConfiguration(
            MyLocationConfiguration.LocationMode.NORMAL, true, currentIcon));

    if (isFirst && type == 1) {
      isFirst = false;
      // 设置默认比例尺15(20-3)
      MapStatusUpdate update =
          MapStatusUpdateFactory.newLatLngZoom(
              new LatLng(cLoc.getLatitude(), cLoc.getLongitude()), baiduMap.getMapStatus().zoom);

      baiduMap.animateMapStatus(update);
    }
  }
    @Override
    public void onReceiveLocation(BDLocation bdLocation) {
      MyLocationData data =
          new MyLocationData.Builder()
              .accuracy(bdLocation.getRadius())
              .latitude(bdLocation.getLatitude())
              .longitude(bdLocation.getLongitude())
              .build();

      mBaiduMap.setMyLocationData(data);
      // mLatitude = 30.67;
      // mLongtitude = 104.06;
      mLatitude = bdLocation.getLatitude();
      mLongtitude = bdLocation.getLongitude();
      myLocation = bdLocation.getAddrStr();

      // Toast.makeText(context,myLocation,Toast.LENGTH_SHORT).show();
      if (isFirstin) {
        // 坐标
        // LatLng latLng = new LatLng(30.67,104.06);
        LatLng latLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());
        MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng);
        mBaiduMap.animateMapStatus(msu);
        isFirstin = false;
        Log.i("map", "first!!!!");
        // Toast.makeText(context,bdLocation.getAddrStr(),Toast.LENGTH_SHORT).show();

      }
    }
    @Override
    public void onReceiveLocation(BDLocation location) {
      MyLocationData data =
          new MyLocationData.Builder() //
              .direction(mCurrentX) // 更新方向
              .accuracy(location.getRadius()) //
              .latitude(location.getLatitude()) //
              .longitude(location.getLongitude())
              .build();
      mBaiduMap.setMyLocationData(data);
      // 设置自定义图标
      MyLocationConfiguration config =
          new MyLocationConfiguration(mLocationMode, true, mIconLocation);
      mBaiduMap.setMyLocationConfigeration(config);
      // 更新经纬度
      mLatitude = location.getLatitude();
      mLongitude = location.getLongitude();

      if (isFirstIn) {
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng);
        mBaiduMap.animateMapStatus(msu);
        isFirstIn = false;

        Toast.makeText(context, location.getAddrStr(), Toast.LENGTH_SHORT).show();
      }
    }
Example #8
0
    @Override
    public void onReceiveLocation(BDLocation location) {
      // TODO Auto-generated method stub
      MyLocationData data =
          new MyLocationData.Builder() //
              .direction(CurrentX) //
              .accuracy(location.getRadius()) //
              .latitude(location.getLatitude()) //
              .longitude(location.getLongitude()) //
              .build();
      MyLocationConfiguration config =
          new MyLocationConfiguration(
              com.baidu.mapapi.map.MyLocationConfiguration.LocationMode.NORMAL,
              true,
              mylocationbitmap);
      mapdu.setMyLocationConfigeration(config);
      mapdu.setMyLocationData(data);
      // 更新经纬度
      latititude = location.getLatitude(); // 把当前的经度保存
      lontitude = location.getLongitude(); // 把当前的纬度保存
      if (firsiIn) {
        LatLng lat = new LatLng(location.getLatitude(), location.getLongitude()); // 获得经度和纬度
        MapStatusUpdate map = MapStatusUpdateFactory.newLatLng(lat);
        mapdu.animateMapStatus(map); // 地图当前位置已动画的形式展现
        firsiIn = false;

        Toast.makeText(context, location.getAddrStr(), Toast.LENGTH_SHORT)
            .show(); // 把当前你所在的位置show出来
      }
    }
  private void initLocClient() {
    // 开启定位图层
    mBaiduMap.setMyLocationEnabled(true);
    mBaiduMap.setMyLocationConfigeration(
        new MyLocationConfigeration(
            com.baidu.mapapi.map.MyLocationConfigeration.LocationMode.NORMAL, true, null));
    // 定位初始化
    mLocClient = new LocationClient(this);
    mLocClient.registerLocationListener(myListener);
    LocationClientOption option = new LocationClientOption();
    option.setProdName("bmobim"); // 设置产品线
    option.setOpenGps(true); // 打开gps
    option.setCoorType("bd09ll"); // 设置坐标类型
    option.setScanSpan(1000);
    option.setOpenGps(true);
    option.setIsNeedAddress(true);
    option.setIgnoreKillProcess(true);
    mLocClient.setLocOption(option);
    mLocClient.start();
    if (mLocClient != null && mLocClient.isStarted()) mLocClient.requestLocation();

    if (lastLocation != null) {
      // 显示在地图上
      LatLng ll = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
      MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
      mBaiduMap.animateMapStatus(u);
    }
  }
Example #10
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_overlay);
   mMapView = (MapView) findViewById(R.id.bmapView);
   mBaiduMap = mMapView.getMap();
   MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(14.0f);
   mBaiduMap.setMapStatus(msu);
   initOverlay();
   mBaiduMap.setOnMarkerClickListener(
       new OnMarkerClickListener() {
         public boolean onMarkerClick(final Marker marker) {
           Button button = new Button(getApplicationContext());
           button.setBackgroundResource(R.drawable.popup);
           OnInfoWindowClickListener listener = null;
           if (marker == mMarkerList.get(0) || marker == mMarkerList.get(3)) {
             button.setText("更改位置");
             listener =
                 new OnInfoWindowClickListener() {
                   public void onInfoWindowClick() {
                     LatLng ll = marker.getPosition();
                     LatLng llNew = new LatLng(ll.latitude + 0.005, ll.longitude + 0.005);
                     marker.setPosition(llNew);
                     mBaiduMap.hideInfoWindow();
                   }
                 };
             LatLng ll = marker.getPosition();
             mInfoWindow =
                 new InfoWindow(BitmapDescriptorFactory.fromView(button), ll, -47, listener);
             mBaiduMap.showInfoWindow(mInfoWindow);
           } else if (marker == mMarkerList.get(1)) {
             button.setText("更改图标");
             button.setOnClickListener(
                 new OnClickListener() {
                   public void onClick(View v) {
                     marker.setIcon(mBitmapList.get(4));
                     mBaiduMap.hideInfoWindow();
                   }
                 });
             LatLng ll = marker.getPosition();
             mInfoWindow = new InfoWindow(button, ll, -47);
             mBaiduMap.showInfoWindow(mInfoWindow);
           } else if (marker == mMarkerList.get(2)) {
             button.setText("删除");
             button.setOnClickListener(
                 new OnClickListener() {
                   public void onClick(View v) {
                     marker.remove();
                     mBaiduMap.hideInfoWindow();
                   }
                 });
             LatLng ll = marker.getPosition();
             mInfoWindow = new InfoWindow(button, ll, -47);
             mBaiduMap.showInfoWindow(mInfoWindow);
           }
           return true;
         }
       });
 }
Example #11
0
  public static MapStatusUpdate newMapStatusWithLatLngArray(LatLng[] ll) {
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    builder.include(ll[1]);
    builder.include(ll[0]);
    LatLngBounds bounds = builder.build();

    MapStatusUpdate mapStatus = MapStatusUpdateFactory.newLatLngBounds(bounds);
    return mapStatus;
  }
Example #12
0
 void loadMarker() {
   for (BranchInfo item : mData) {
     if (item.getLat() == 0 || item.getLng() == 0) continue;
     LatLng latLng = new LatLng(item.getLat(), item.getLng());
     Marker marker =
         (Marker)
             mBaiduMap.addOverlay(
                 new MarkerOptions()
                     .position(latLng)
                     .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_map_marker)));
     Bundle bundle = new Bundle();
     bundle.putSerializable("info", item);
     marker.setExtraInfo(bundle);
     // 将地图移到到最后一个经纬度位置
     MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(latLng);
     mBaiduMap.setMapStatus(u);
   }
   mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newLatLng(mMyLocation));
 }
Example #13
0
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    view = inflater.inflate(R.layout.yiyaogongsi, null);
    mContext = getActivity();
    mMapView = (MapView) view.findViewById(R.id.bmapView);
    mBaiduMap = mMapView.getMap();
    MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(14.0f);
    mBaiduMap.setMapStatus(msu);
    LatLng ll =
        new LatLng(
            Double.parseDouble(AmbServicesFragment.lat),
            Double.parseDouble("" + AmbServicesFragment.Long));
    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);

    if (u != null && mBaiduMap != null) {
      mBaiduMap.animateMapStatus(u);
    }
    getDate();
    return view;
  }
Example #14
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
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   SDKInitializer.initialize(getApplicationContext());
   setContentView(R.layout.activity_main);
   this.context = this;
   mapView = (MapView) findViewById(R.id.bmapView);
   // 设置初始的地图比例  500米
   mBaiduMap = mapView.getMap();
   MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f);
   mBaiduMap.setMapStatus(msu);
   // 初始化定位
   initLocation();
 }
Example #16
0
  /** 放大级别 3 - 19 */
  @SuppressLint("NewApi")
  private void perfomZoom(boolean isZoomIn) {
    try {
      MapStatusUpdate u;
      zoomLevel = mBaiduMap.getMapStatus().zoom;
      if (isZoomIn) {
        zoomOutButton.setImageResource(R.drawable.main_icon_zoomout);
        if (zoomLevel + 0.5 < mBaiduMap.getMaxZoomLevel() * 0.9) {
          zoomLevel += 0.5;
          u = MapStatusUpdateFactory.zoomTo(zoomLevel);
        } else {
          zoomLevel = (float) (mBaiduMap.getMaxZoomLevel() * 0.9);
          u = MapStatusUpdateFactory.zoomTo(zoomLevel);
          zoomInButton.setImageResource(R.drawable.main_icon_zoomin_dis);
        }
        zoomInButton.setBackground(
            getResources().getDrawable(R.drawable.main_widget_bottombutton_selector));

      } else {
        zoomInButton.setImageResource(R.drawable.main_icon_zoomin);
        if (zoomLevel - 0.5 > mBaiduMap.getMinZoomLevel() + 5) {
          zoomLevel -= 0.5;
          u = MapStatusUpdateFactory.zoomTo(zoomLevel);
        } else {
          zoomLevel = mBaiduMap.getMinZoomLevel() + 5;
          u = MapStatusUpdateFactory.zoomTo(zoomLevel);
          zoomOutButton.setImageResource(R.drawable.main_icon_zoomout_dis);
        }
        zoomOutButton.setBackground(
            getResources().getDrawable(R.drawable.main_widget_bottombutton_selector));
      }

      mBaiduMap.animateMapStatus(u);
    } catch (NumberFormatException e) {
      e.printStackTrace();
    }
  }
Example #17
0
  public void initOverlay() {
    // add marker overlay
    addOverlay(39.963175, 116.400244, R.drawable.icon_marka, 9);
    addOverlay(39.942821, 116.369199, R.drawable.icon_markb, 5);
    MarkerOptions ooC = (MarkerOptions) addOverlay(39.939723, 116.425541, R.drawable.icon_markc, 7);
    MarkerOptions ooD = (MarkerOptions) addOverlay(39.906965, 116.401394, R.drawable.icon_markd, 0);
    ooC.perspective(false).anchor(0.5f, 0.5f).rotate(30);
    ooD.period(10);

    //		ArrayList<BitmapDescriptor> giflist = new ArrayList<BitmapDescriptor>();
    //		giflist.add(bdA);
    //		giflist.add(bdB);
    //		giflist.add(bdC);

    BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
    mBitmapList.add(bd);
    // add ground overlay
    LatLng southwest = new LatLng(39.92235, 116.380338);
    LatLng northeast = new LatLng(39.947246, 116.414977);
    LatLngBounds bounds = new LatLngBounds.Builder().include(northeast).include(southwest).build();

    BitmapDescriptor bdGround = BitmapDescriptorFactory.fromResource(R.drawable.ground_overlay);

    mBitmapList.add(bdGround);
    OverlayOptions ooGround =
        new GroundOverlayOptions().positionFromBounds(bounds).image(bdGround).transparency(0.8f);
    mBaiduMap.addOverlay(ooGround);

    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(bounds.getCenter());
    mBaiduMap.setMapStatus(u);

    mBaiduMap.setOnMarkerDragListener(
        new OnMarkerDragListener() {
          public void onMarkerDrag(Marker marker) {}

          public void onMarkerDragEnd(Marker marker) {
            Toast.makeText(
                    OverlayDemo.this,
                    "拖拽结束,新位置:"
                        + marker.getPosition().latitude
                        + ", "
                        + marker.getPosition().longitude,
                    Toast.LENGTH_LONG)
                .show();
          }

          public void onMarkerDragStart(Marker marker) {}
        });
  }
 @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();
   }
 }
Example #19
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));
  }
  /**
   * 节点浏览示例
   *
   * @param v
   */
  public void nodeClick(View v) {
    if (route == null || route.getAllStep() == null) {
      return;
    }
    if (nodeIndex == -1 && v.getId() == R.id.pre) {
      return;
    }
    // 设置节点索引
    if (v.getId() == R.id.next) {
      if (nodeIndex < route.getAllStep().size() - 1) {
        nodeIndex++;
      } else {
        return;
      }
    } else if (v.getId() == R.id.pre) {
      if (nodeIndex > 0) {
        nodeIndex--;
      } else {
        return;
      }
    }
    // 获取节结果信息
    LatLng nodeLocation = null;
    String nodeTitle = null;
    Object step = route.getAllStep().get(nodeIndex);
    if (step instanceof DrivingRouteLine.DrivingStep) {
      nodeLocation = ((DrivingRouteLine.DrivingStep) step).getEntrance().getLocation();
      nodeTitle = ((DrivingRouteLine.DrivingStep) step).getInstructions();
    } else if (step instanceof WalkingRouteLine.WalkingStep) {
      nodeLocation = ((WalkingRouteLine.WalkingStep) step).getEntrance().getLocation();
      nodeTitle = ((WalkingRouteLine.WalkingStep) step).getInstructions();
    } else if (step instanceof TransitRouteLine.TransitStep) {
      nodeLocation = ((TransitRouteLine.TransitStep) step).getEntrance().getLocation();
      nodeTitle = ((TransitRouteLine.TransitStep) step).getInstructions();
    }

    if (nodeLocation == null || nodeTitle == null) {
      return;
    }
    // 移动节点至中心
    mBaidumap.setMapStatus(MapStatusUpdateFactory.newLatLng(nodeLocation));
    // show popup
    popupText = new TextView(RoutePlanDemo.this);
    popupText.setBackgroundResource(R.drawable.popup);
    popupText.setTextColor(0xFF000000);
    popupText.setText(nodeTitle);
    mBaidumap.showInfoWindow(new InfoWindow(popupText, nodeLocation, 0));
  }
 @Override
 public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
   if (reverseGeoCodeResult == null
       || reverseGeoCodeResult.error != SearchResult.ERRORNO.NO_ERROR) {
     Toast.makeText(NewMapActivity.this, "抱歉,未能找到结果", Toast.LENGTH_LONG).show();
     return;
   }
   mBaiduMap.clear();
   mBaiduMap.addOverlay(
       new MarkerOptions()
           .position(reverseGeoCodeResult.getLocation())
           .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marka)));
   mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(reverseGeoCodeResult.getLocation()));
   Toast.makeText(NewMapActivity.this, reverseGeoCodeResult.getAddress(), Toast.LENGTH_LONG)
       .show();
 }
    @Override
    public void onReceiveLocation(BDLocation location) {
      // map view 销毁后不在处理新接收的位置
      if (location == null || mapView == null) return;

      if (lastLocation != null) {
        if (lastLocation.getLatitude() == location.getLatitude()
            && lastLocation.getLongitude() == location.getLongitude()) {
          Logger.d(getString(R.string.chat_geoIsSame)); // 若两次请求获取到的地理位置坐标是相同的,则不再定位
          locClient.stop();
          return;
        }
      }
      lastLocation = location;

      Logger.d(
          "lontitude = "
              + location.getLongitude()
              + ",latitude = "
              + location.getLatitude()
              + ","
              + getString(R.string.chat_position)
              + " = "
              + lastLocation.getAddrStr());

      MyLocationData locData =
          new MyLocationData.Builder()
              .accuracy(location.getRadius())
              // 此处设置开发者获取到的方向信息,顺时针0-360
              .direction(100)
              .latitude(location.getLatitude())
              .longitude(location.getLongitude())
              .build();
      baiduMap.setMyLocationData(locData);
      LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
      String address = location.getAddrStr();
      if (address != null && !address.equals("")) {
        lastLocation.setAddrStr(address);
      } else {
        // 反Geo搜索
        geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(ll));
      }
      // 显示在地图上
      MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
      baiduMap.animateMapStatus(u);
      // 设置按钮可点击
    }
Example #23
0
 private void showMap(double latitude, double longtitude, String address) {
   // sendButton.setVisibility(View.GONE);
   LatLng llA = new LatLng(latitude, longtitude);
   CoordinateConverter converter = new CoordinateConverter();
   converter.coord(llA);
   converter.from(CoordinateConverter.CoordType.COMMON);
   LatLng convertLatLng = converter.convert();
   OverlayOptions ooA =
       new MarkerOptions()
           .position(convertLatLng)
           .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marka))
           .zIndex(4)
           .draggable(true);
   mBaiduMap.addOverlay(ooA);
   MapStatusUpdate u = MapStatusUpdateFactory.newLatLngZoom(convertLatLng, 17.0f);
   mBaiduMap.animateMapStatus(u);
 }
Example #24
0
 @Override
 public void onClick(View v) {
   int id = v.getId();
   if (id == R.id.tanchu) {
     if (flag == 1) {
       View aaa = getLayoutInflater().inflate(R.layout.style_map, null);
       window = new PopupWindow(aaa, 100, 150);
       window.showAtLocation(aaa, Gravity.BOTTOM | Gravity.CENTER, -100, -25);
       one = (TextView) aaa.findViewById(R.id.common_map);
       two = (TextView) aaa.findViewById(R.id.star_map);
       three = (TextView) aaa.findViewById(R.id.traffic_map);
       mylocate = (TextView) aaa.findViewById(R.id.mylocate);
       addwu = (TextView) aaa.findViewById(R.id.add);
       one.setOnClickListener(this);
       two.setOnClickListener(this);
       three.setOnClickListener(this);
       mylocate.setOnClickListener(this);
       addwu.setOnClickListener(this);
       flag = 2;
     } else {
       if (window != null && window.isShowing()) {
         window.dismiss();
         flag = 1;
       }
     }
   } else if (id == R.id.common_map) {
     mapdu.setMapType(BaiduMap.MAP_TYPE_NORMAL);
   } else if (id == R.id.star_map) {
     mapdu.setMapType(BaiduMap.MAP_TYPE_SATELLITE);
   } else if (id == R.id.traffic_map) {
     if (mapdu.isTrafficEnabled()) {
       mapdu.setTrafficEnabled(false);
     } else {
       mapdu.setTrafficEnabled(true);
     }
   } else if (id == R.id.mylocate) {
     LatLng lat = new LatLng(latititude, lontitude); // 获得经度和纬度
     MapStatusUpdate map = MapStatusUpdateFactory.newLatLng(lat);
     mapdu.animateMapStatus(map); // 地图当前位置已动画的形式展现
   } else if (id == R.id.add) {
     info ii = new info();
     ii.jianli();
     AddOverly(ii.hhh);
   }
 }
  // 定位到我的位置
  private void CenterToMyLocation() {
    LatLng latLng = new LatLng(mLatitude, mLongtitude);
    LatLng latLng2 = new LatLng(mLatitude2, mLongtitude2);
    MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng);
    mBaiduMap.animateMapStatus(msu);
    // 坐标搜索
    PlanNode stNode2 = PlanNode.withLocation(latLng);
    PlanNode enNode2 = PlanNode.withLocation(latLng2);
    String strInfo = String.format("起点坐标纬度:%f 经度:%f", mLatitude, mLongtitude);
    String endInfo = String.format("终点坐标纬度:%f 经度:%f", mLatitude2, mLongtitude2);

    Log.i("baidu", strInfo);
    Log.i("baidu", endInfo);
    // PlanNode stNode = PlanNode.withCityNameAndPlaceName("成都", myLocation);
    // PlanNode enNode = PlanNode.withCityNameAndPlaceName("成都", endaddress);

    mSearch.walkingSearch((new WalkingRoutePlanOption()).from(stNode2).to(enNode2));
  }
Example #26
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "[ACTIVITY] onCreate");
    super.onCreate(savedInstanceState);
    instance = this;
    // 在使用SDK各组件之前初始化context信息,传入ApplicationContext
    // 注意该方法要再setContentView方法之前实现
    SDKInitializer.initialize(getApplicationContext());
    mStepValue = 0;
    mPaceValue = 0;

    setContentView(R.layout.layoutmain);

    mUtils = Utils.getInstance();
    mMapView = (MapView) findViewById(R.id.bmapView);
    // sendButton = (Button) findViewById(R.id.btn_location_send);
    Intent intent = getIntent();
    double latitude = intent.getDoubleExtra("latitude", 0);
    mCurrentMode = LocationMode.NORMAL;
    mBaiduMap = mMapView.getMap();
    MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f);
    mBaiduMap.setMapStatus(msu);
    initMapView();
    if (latitude == 0) {
      mMapView = new MapView(this, new BaiduMapOptions());
      mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, null));
      showMapWithLocationClient();
    } else {
      double longtitude = intent.getDoubleExtra("longitude", 0);
      String address = intent.getStringExtra("address");
      LatLng p = new LatLng(latitude, longtitude);
      mMapView =
          new MapView(
              this, new BaiduMapOptions().mapStatus(new MapStatus.Builder().target(p).build()));
      showMap(latitude, longtitude, address);
    }
    // 注册 SDK 广播监听者
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
    iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
    mBaiduReceiver = new BaiduSDKReceiver();
    registerReceiver(mBaiduReceiver, iFilter);
  }
  private void addOverlays(List<Info> infos) {
    // 添加覆盖物
    mBaiduMap.clear();
    LatLng latLng = null;
    Marker marker = null;
    OverlayOptions options;
    for (Info info : infos) {
      // 经纬度
      latLng = new LatLng(info.getLatitude(), info.getLongitude());
      // 图标
      options = new MarkerOptions().position(latLng).icon(mMarker).zIndex(5);
      marker = (Marker) mBaiduMap.addOverlay(options);
      Bundle bundle = new Bundle();
      bundle.putSerializable("info", info);
      marker.setExtraInfo(bundle);
    }

    MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng);
    mBaiduMap.setMapStatus(msu);
  }
  @Override
  public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
    if (geoCodeResult == null || geoCodeResult.error != SearchResult.ERRORNO.NO_ERROR) {
      Toast.makeText(NewMapActivity.this, "抱歉,未能找到结果", Toast.LENGTH_LONG).show();
      return;
    }
    mBaiduMap.clear();
    //        mBaiduMap.addOverlay(new MarkerOptions().position(geoCodeResult.getLocation())
    //                .icon(BitmapDescriptorFactory
    //                        .fromResource(R.drawable.icon_marka)));
    mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(geoCodeResult.getLocation()));
    mLatitude2 = geoCodeResult.getLocation().latitude;
    mLongtitude2 = geoCodeResult.getLocation().longitude;
    String strInfo =
        String.format(
            "纬度:%f 经度:%f",
            geoCodeResult.getLocation().latitude, geoCodeResult.getLocation().longitude);
    // Toast.makeText(NewMapActivity.this, strInfo, Toast.LENGTH_LONG).show();

  }
Example #29
0
 @Override
 public void onReceiveLocation(BDLocation location) {
   // map view 销毁后不在处理新接收的位置
   if (location == null || mMapView == null) return;
   MyLocationData locData =
       new MyLocationData.Builder()
           .accuracy(location.getRadius())
           // 此处设置开发者获取到的方向信息,顺时针0-360
           .direction(100)
           .latitude(location.getLatitude())
           .longitude(location.getLongitude())
           .build();
   mBaiduMap.setMyLocationData(locData);
   if (isFirstLoc) {
     isFirstLoc = false;
     mMyLocation = new LatLng(location.getLatitude(), location.getLongitude());
     mAdapter.setLocation(mMyLocation);
     MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(mMyLocation);
     mBaiduMap.animateMapStatus(u);
   }
 }
Example #30
0
  private void initBaiduMap() {
    mMapView = (MapView) findViewById(R.id.bmapView);
    mBaiduMap = mMapView.getMap();
    mBaiduMap.setMaxAndMinZoomLevel(18, 13);

    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
    iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
    mReceiver = new BaiduReceiver();
    registerReceiver(mReceiver, iFilter);

    Intent intent = getIntent();
    String type = intent.getStringExtra("type");
    if (type.equals("select")) { // 聊天选择位置
      initTopBarForBoth(
          "我的位置",
          R.drawable.base_action_bar_true_bg_selector,
          new onRightImageButtonClickListener() {

            @Override
            public void onClick() {
              goToChatPage();
              Log.i("地图", "点击确定");
            }
          });
      // 获取位置后再设置为可点击
      mHeadLayout.getRightImageButton().setEnabled(false);
      initLocClient();
    } else { // 查看当前位置
      initTopBarForLeft("位置");
      Bundle b = intent.getExtras();
      LatLng latlng = new LatLng(b.getDouble("latitude"), b.getDouble("longitude"));
      mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(latlng));
      // 显示当前位置图标
      OverlayOptions ooA = new MarkerOptions().position(latlng).icon(bdgeo).zIndex(9);
      mBaiduMap.addOverlay(ooA);
    }
    mSearch = GeoCoder.newInstance();
    mSearch.setOnGetGeoCodeResultListener(this);
  }