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);
    }
  }
    @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();
      }
    }
Esempio n. 3
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出来
      }
    }
Esempio n. 4
0
  /**
   * 把一个坐标点显示在地图上面.
   *
   * @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;
          }
        });
  }
Esempio n. 5
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);
      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);
      }
    }
    @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();

      }
    }
Esempio n. 7
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);
      }
    }
Esempio n. 8
0
  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);
    }
  }
Esempio n. 9
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));
 }
Esempio n. 10
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) {}
        });
  }
  /**
   * 节点浏览示例
   *
   * @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));
  }
Esempio n. 12
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);
      // 设置按钮可点击
    }
Esempio n. 14
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);
   }
 }
Esempio n. 15
0
  // 定位到我的位置
  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));
  }
Esempio n. 16
0
  @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();

  }
  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);
  }
Esempio n. 18
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;
  }
Esempio n. 19
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);
   }
 }
Esempio n. 20
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);
  }
Esempio n. 21
0
  /**
   * 把点增加到图上面
   *
   * @param mMapView
   * @param list 点的信息
   * @param image 默认图片资源id
   */
  public void addPt(final BaiduMap mBaiduMap, final List<MyPoint> list, int image) {

    mBaiduMap.clear();
    BitmapDescriptor bdA = BitmapDescriptorFactory.fromResource(R.drawable.icon_geo);
    final List<Marker> markerList = new ArrayList<Marker>();
    for (int i = 0; i < list.size(); i++) {
      LatLng llA = new LatLng(list.get(i).getLat(), list.get(i).getLng());
      OverlayOptions ooA = new MarkerOptions().position(llA).icon(bdA).zIndex(9).draggable(true);
      markerList.add((Marker) (mBaiduMap.addOverlay(ooA)));
    }
    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(getCenterPointer(list));
    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;
            for (int i = 0; i < list.size(); i++) {
              if (marker == markerList.get(i)) {
                button.setText(list.get(i).getName());
                break;
              }
            }
            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;
          }
        });
  }
Esempio n. 22
0
 /**
  * 添加覆盖物
  *
  * @param hhh
  */
 private void AddOverly(List<info> hhh) {
   // TODO Auto-generated method stub
   mapdu.clear(); // 清楚图层上的东西
   // 定义经纬度
   LatLng latlng = null;
   Marker marker = null;
   OverlayOptions options;
   // 进行一个循环
   for (info nihao : hhh) {
     // 经纬度
     latlng = new LatLng(nihao.getLatitude(), nihao.getLongitude());
     // 图标
     options = new MarkerOptions().position(latlng).icon(mMarker).zIndex(5); // 添加到图层的最高层
     marker = (Marker) mapdu.addOverlay(options);
     // marker携带一些值
     Bundle bundle = new Bundle();
     bundle.putSerializable("info", nihao); // 实例化对象
     marker.setExtraInfo(bundle); // marker 携带信息也就是info类表中的信息
   }
   // 每次添加完图层的时候,把地图移动到第一个图层的位置
   MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latlng);
   mapdu.setMapStatus(msu);
 }
Esempio n. 23
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));
  }
Esempio n. 24
0
 /** 定位并移动地图 */
 private void centerToCurrentPlace() {
   MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(locationListener.getLatLng());
   map.animateMapStatus(msu);
 }
Esempio n. 25
0
    @Override
    public void onReceiveLocation(BDLocation location) {

      if (location == null || mMapView == null) return;
      MyLocationData locData =
          new MyLocationData.Builder()
              .accuracy(location.getRadius())
              .direction(mXDirection)
              .latitude(location.getLatitude())
              .longitude(location.getLongitude())
              .build();

      mCurrentAccracy = location.getRadius();

      mBaiduMap.setMyLocationData(locData);

      mCurrentLantitude = location.getLatitude();
      mCurrentLongitude = location.getLongitude();

      OneBusApplication.CURRENT_POSITION = location.getAddrStr();
      LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());

      OneBusApplication.CURRENT_LOCATION = ll;

      if (location.getCity() != null) {
        OneBusApplication.GPS_CITY = location.getCity();
      }

      // Log.i("Coortype ",
      // ""+location.getNetworkLocationType()+" : "+location.getCoorType()+"
      // City:"+location.getCity());

      if (isFirstLoc) {
        isFirstLoc = false;
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        mBaiduMap.animateMapStatus(u);

        if (location.getCity() != null) {
          Log.i("MainActivity", "SharedPreferences Save Location And City");
          SharedPreferences preferences =
              getSharedPreferences("LastLocation", Context.MODE_PRIVATE);
          Editor editor = preferences.edit();
          if (preferences.getBoolean("isFirstLocate", true)) {
            OneBusApplication.CURRENT_CITY = location.getCity(); // If
            // is
            // the
            // first
            // locate,
            editor.putBoolean("isFirstLocate", false); // set the
            // current
            // city as
            // GpsCity
          }

          editor.putString("currentCity", location.getCity());
          editor.putString("LastAddress", location.getAddrStr());
          editor.commit();
          preferences = null;
          editor = null;
        }

        initNearby();
      }
    }
Esempio n. 26
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SDKInitializer.initialize(getApplicationContext());
    setContentView(R.layout.activity_main);
    b = (Button) findViewById(R.id.shit);
    c = (Button) findViewById(R.id.shit2);
    n = (NumberPicker) findViewById(R.id.num);
    n.setMaxValue(5);
    n.setMinValue(0);

    ////        b.setVisibility(View.INVISIBLE);
    map = file();
    map2 = file2();
    mMapView = (MapView) findViewById(R.id.bmapView);
    mBaiduMap = mMapView.getMap();
    MapStatusUpdate u = MapStatusUpdateFactory.zoomTo(10.0f);
    mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(new LatLng(31.083236, 121.394725)));
    mBaiduMap.animateMapStatus(u);
    b.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            heatmap.removeHeatMap();
            //                for(String name:map2.keySet()){
            //                    LatLng ptCenter=new LatLng(map2.get(name)[0],map2.get(name)[1]);
            //                    mBaiduMap.addOverlay(new MarkerOptions().position(ptCenter)
            //                            .icon(BitmapDescriptorFactory
            //
            // .fromResource(R.drawable.shit)).perspective(true));
            //                }
          }
        });
    c.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (heatmap != null) heatmap.removeHeatMap();
            int time = 0;
            switch (n.getValue()) {
              case 0:
                time = 4;
                break;
              case 1:
                time = 8;
                break;
              case 2:
                time = 10;
                break;
              case 3:
                time = 16;
                break;
              case 4:
                time = 18;
                break;
              case 5:
                time = 22;
                break;
            }
            //                int[] DEFAULT_GRADIENT_COLORS = {Color.rgb(255, 255, 0),Color.rgb(255,
            // 200, 0),Color.rgb(255, 155, 0) ,Color.rgb(255, 100, 0),Color.rgb(255, 55,
            // 0),Color.rgb(255, 0, 0) };
            int[] DEFAULT_GRADIENT_COLORS = {Color.rgb(255, 255, 0), Color.rgb(255, 0, 0)};
            // 设置渐变颜色起始值
            float[] DEFAULT_GRADIENT_START_POINTS = {0.2f, 1f};
            //                float[] DEFAULT_GRADIENT_START_POINTS = { 0f,0.2f, 0.4f,0.6f,0.8f,1f
            // };
            // 构造颜色渐变对象1
            List<WeightedLatLng> l = new ArrayList<WeightedLatLng>();
            for (String n : map.keySet()) {
              if (!map2.containsKey(n) | !map.get(n).containsKey(time)) {
                Log.e(TAG, n);
                continue;
              }
              WeightedLatLng ll =
                  new WeightedLatLng(
                      new LatLng(map2.get(n)[0], map2.get(n)[1]), map.get(n).get(time));
              l.add(ll);
            }
            Gradient gradient =
                new Gradient(DEFAULT_GRADIENT_COLORS, DEFAULT_GRADIENT_START_POINTS);

            heatmap = new HeatMap.Builder().weightedData(l).gradient(gradient).radius(20).build();
            // 在地图上添加热力图
            mBaiduMap.addHeatMap(heatmap);
          }
        });
    // 设置渐变颜色值

  }
  private void initialLayout() {
    mLatitude = Double.parseDouble(preference.getString("latitude", "0.00"));
    mLongitude = Double.parseDouble(preference.getString("longitude", "0.00"));

    mapView = (MapView) findViewById(R.id.mapView);
    // 去掉百度Logo
    int count = mapView.getChildCount();
    for (int i = 0; i < count; i++) {
      View child = mapView.getChildAt(i);
      if (child instanceof ImageView) {
        child.setVisibility(View.INVISIBLE);
      }
    }

    baiduMap = mapView.getMap();
    // 初始化地图位置
    locLatLng = new LatLng(mLatitude, mLongitude);
    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(locLatLng);
    baiduMap.animateMapStatus(u);

    // 设置地图放大级别 0-19
    MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(17);
    baiduMap.animateMapStatus(msu);

    // 开启定位图层
    baiduMap.setMyLocationEnabled(true);
    // 自定义Maker
    BitmapDescriptor mCurrentMarker =
        BitmapDescriptorFactory.fromResource(R.drawable.icon_arrow_up);

    baiduMap.setOnMapClickListener(
        new OnMapClickListener() {

          @Override
          public boolean onMapPoiClick(MapPoi mapPoi) {
            clickLatLng = mapPoi.getPosition();
            addMakerToMap(clickLatLng);
            isClick = true;

            Toast.makeText(
                    getApplicationContext(),
                    "您选中了:" + mapPoi.getName().replace("\\", ""),
                    Toast.LENGTH_SHORT)
                .show();

            return false;
          }

          @Override
          public void onMapClick(LatLng latLng) {
            clickLatLng = latLng;
            addMakerToMap(clickLatLng);
            isClick = true;
          }
        });

    layoutConfirm = (RelativeLayout) findViewById(R.id.layoutConfirm);
    layoutConfirm.setOnClickListener(new MyOnClickListener());
    btnConfirm = (Button) findViewById(R.id.btnConfirm);
    btnConfirm.setOnClickListener(new MyOnClickListener());

    layoutBack = (RelativeLayout) findViewById(R.id.layoutBack);
    layoutBack.setOnClickListener(new MyOnClickListener());
    btnBack = (Button) findViewById(R.id.btnBack);
    btnBack.setOnClickListener(new MyOnClickListener());

    textHint = (TextView) findViewById(R.id.textHint);
    imageHandClick = (ImageView) findViewById(R.id.imageHandClick);
  }
 /** 定位到我的位置 */
 private void centerToMylocation() {
   LatLng latLng = new LatLng(mLatitude, mLongitude);
   MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng);
   mBaiduMap.animateMapStatus(msu);
 }