Ejemplo n.º 1
0
 void initView() {
   toolbar = (Toolbar) findViewById(R.id.toolbar);
   mapView = (MapView) findViewById(R.id.mapview);
   fab = (FloatingActionButton) findViewById(R.id.fab);
   bd = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
   info = BitmapDescriptorFactory.fromResource(R.drawable.popup);
   drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
 }
Ejemplo n.º 2
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) {}
        });
  }
Ejemplo n.º 3
0
 private void locateMyLocation(UserShakeData userShakeData) {
   LatLng cenpt = new LatLng(userShakeData.getLatitude(), userShakeData.getLongitude());
   locatePotin(cenpt);
   BitmapDescriptor markIcon = BitmapDescriptorFactory.fromResource(R.drawable.lj_map_my_location);
   OverlayOptions option = new MarkerOptions().position(cenpt).icon(markIcon);
   myContext.baiduMap.addOverlay(option);
 }
Ejemplo n.º 4
0
 @Override
 public BitmapDescriptor getTerminalMarker() {
   if (useDefaultIcon) {
     return BitmapDescriptorFactory.fromResource(R.drawable.icon_en);
   }
   return null;
 }
  private void initLocation() {

    mLocationMode = com.baidu.mapapi.map.MyLocationConfiguration.LocationMode.NORMAL;
    mLocationClient = new LocationClient(this);
    mLocationListener = new MyLocationListener();
    mLocationClient.registerLocationListener(mLocationListener);

    LocationClientOption option = new LocationClientOption();
    option.setCoorType("bd09ll");
    option.setIsNeedAddress(true);
    option.setOpenGps(true);
    option.setScanSpan(1000);

    mLocationClient.setLocOption(option);
    // 初始化图标
    mIconLocation = BitmapDescriptorFactory.fromResource(R.drawable.navi_map_gps_locked);

    myOrientationListener = new MyOrientationListener(context);

    myOrientationListener.setOnOrientationListener(
        new OnOrientationListener() {

          @Override
          public void onOrientationChanged(float x) {
            mCurrentX = x;
          }
        });
  }
Ejemplo n.º 6
0
  private void initLocation() {
    // TODO Auto-generated method stub
    client = new LocationClient(this);
    locationlistener = new Mylocation();
    client.registerLocationListener(locationlistener);
    // 设置location的一些参数
    LocationClientOption option = new LocationClientOption();
    option.setCoorType("bd09ll");
    option.setIsNeedAddress(true); // 获得当前的地址
    option.setOpenGps(true);
    option.setScanSpan(1000);
    client.setLocOption(option); // 设置完成上述功能
    // 初始化图标
    mylocationbitmap = BitmapDescriptorFactory.fromResource(R.drawable.arrow);
    // 初始化 方向传感器
    myorientaion = new MyOrientation(this);
    myorientaion.setChanged(
        new OrientainChanged() {

          @Override
          public void Onchanged(float x) {
            // TODO Auto-generated method stub
            CurrentX = x;
          }
        });
  }
Ejemplo n.º 7
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;
          }
        });
  }
Ejemplo n.º 8
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);
    }
  }
Ejemplo n.º 9
0
 private void drawAreadyLin(List<LatLng> agoList) {
   BitmapDescriptor custom1 = BitmapDescriptorFactory.fromResource(R.drawable.icon_road_red_arrow);
   OverlayOptions ooPolyline =
       new PolylineOptions().width(15).color(0xAAFF0000).points(agoList).customTexture(custom1);
   // .textureIndex(index);
   // 添加到地图
   mBaiduMap.addOverlay(ooPolyline);
 }
Ejemplo n.º 10
0
 private MarkerOptions addOverlay(double lat, double lng, int resID, int zIndex) {
   LatLng llA = new LatLng(lat, lng);
   BitmapDescriptor bdA = BitmapDescriptorFactory.fromResource(resID);
   mBitmapList.add(bdA);
   MarkerOptions ooA = new MarkerOptions().position(llA).icon(bdA).zIndex(zIndex).draggable(true);
   mMarkerList.add((Marker) mBaiduMap.addOverlay(ooA));
   return ooA;
 }
Ejemplo n.º 11
0
  private void addMakerToMap(LatLng latLng) {
    // 隐藏食指点击动画
    // imageHandClick.setVisibility(View.GONE);

    baiduMap.clear();
    BitmapDescriptor bitmapDescriptor =
        BitmapDescriptorFactory.fromResource(R.drawable.ui_marker_select);

    OverlayOptions ooA =
        new MarkerOptions().position(latLng).icon(bitmapDescriptor).zIndex(9).draggable(true);
    baiduMap.addOverlay(ooA);
  }
Ejemplo n.º 12
0
 private void drawLines(double oldLat, double newLat, double oldLng, double newLng) {
   // TODO Auto-generated method stub
   // 绘制纹理图
   BitmapDescriptor custom1 = BitmapDescriptorFactory.fromResource(R.drawable.icon_road_red_arrow);
   Log.e("old", oldLat + "<==" + oldLng + "--" + newLat + "<==" + newLng);
   LatLng pt1 = new LatLng(oldLat, oldLng);
   LatLng pt2 = new LatLng(newLat, newLng);
   points.add(pt1); // 点元素
   points.add(pt2); // 点元素
   OverlayOptions ooPolyline =
       new PolylineOptions().width(15).color(0xAAFF0000).points(points).customTexture(custom1);
   mBaiduMap.addOverlay(ooPolyline);
 }
Ejemplo n.º 13
0
    private void setMarkerIcon(Marker marker, boolean focused) {

      if (marker == null) return;

      int pos = marker.getZIndex();

      BitmapDescriptor descriptor =
          BitmapDescriptorFactory.fromResource(
              focused
                  ? marker_focus_icon_ids[pos % marker_focus_icon_ids.length]
                  : marker_icon_ids[pos % marker_icon_ids.length]);

      marker.setIcon(descriptor);
    }
Ejemplo n.º 14
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();
 }
Ejemplo n.º 15
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);
 }
Ejemplo n.º 16
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));
 }
Ejemplo n.º 17
0
  private void addlayout(String lat, String lng, String name, String adress, String phone) {
    LatLng ll =
        new LatLng(Double.parseDouble("" + lat) - 0.00005, Double.parseDouble("" + lng) - 0.00005);
    View view2 = LayoutInflater.from(mContext).inflate(R.layout.over_map, null);
    ((TextView) view2.findViewById(R.id.hospital_name)).setText("医院:" + name);
    ((TextView) view2.findViewById(R.id.adress)).setText("地址:" + adress);
    ((TextView) view2.findViewById(R.id.phone))
        .setText("距离:" + Float.parseFloat(phone) / 1000 + "km");
    BitmapDescriptor bdA = BitmapDescriptorFactory.fromBitmap(textTobimap(view2));
    OverlayOptions ooA = new MarkerOptions().position(ll).icon(bdA).zIndex(9).draggable(true);
    mBaiduMap.addOverlay(ooA);

    LatLng point = new LatLng(Double.parseDouble("" + lat), Double.parseDouble("" + lng));
    // 构建Marker图标
    BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_marka);
    // 构建MarkerOption,用于在地图上添加Marker
    OverlayOptions option = new MarkerOptions().position(point).icon(bitmap);
    // 在地图上添加Marker,并显示
    mBaiduMap.addOverlay(option);
  }
Ejemplo n.º 18
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;
          }
        });
  }
Ejemplo n.º 19
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;
      mBaiduMap.clear();
      LatLng llA = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
      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);
    }
Ejemplo n.º 20
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));
  }
Ejemplo n.º 21
0
        /**
         * 地图长按事件监听回调函数
         *
         * @param point 长按的地理坐标
         */
        public void onMapLongClick(LatLng point) {
          hasEndpoint = true;
          // 构建Marker图标
          BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_marka);
          // 构建MarkerOption,用于在地图上添加Marker
          OverlayOptions option = new MarkerOptions().position(point).icon(bitmap);
          Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
          getSystemService(VIBRATOR_SERVICE);
          // 震动30ms
          vibrator.vibrate(30);
          // 清除Marker
          mBaiduMap.clear();
          // 在地图上添加Marker,并显示
          mBaiduMap.addOverlay(option);
          Toast.makeText(NavigateActivity.this, "设置为终点", Toast.LENGTH_SHORT).show();

          EditText mDest = (EditText) findViewById(R.id.et_destination);
          mDest.setText("经度:" + point.longitude + " 纬度:" + point.latitude);
          destLoc.setLongitude(point.longitude);
          destLoc.setLatitude(point.latitude);
          System.out.println("终点");
          System.out.println("经度:" + destLoc.getLongitude());
          System.out.println("纬度:" + destLoc.getLatitude());
        }
Ejemplo n.º 22
0
  private void addMarker2Map() {

    List<OverlayOptions> optionses = new ArrayList<OverlayOptions>();

    for (int i = 0; i < data.size(); i++) {

      MyPoiInfo info = data.get(i);
      BitmapDescriptor descriptor =
          BitmapDescriptorFactory.fromResource(marker_icon_ids[i % marker_icon_ids.length]);
      OverlayOptions oo =
          new MarkerOptions()
              .position(new LatLng(info.lat, info.lng))
              .icon(descriptor)
              .zIndex(i)
              .title(info.name);
      optionses.add(oo);
    }

    overlayManager = new MarkerOverLayManager(baiduMap, optionses);
    overlayManager.addToMap();
    // add maker click listener
    baiduMap.setOnMarkerClickListener(overlayManager);
    baiduMap.removeMarkerClickListener(drivingRouteOverlay);
  }
Ejemplo n.º 23
0
public class LocationActivity extends BaseActivity implements OnGetGeoCoderResultListener {

  MapView mMapView;
  BaiduMap mBaiduMap;
  // 定位相关
  LocationClient mLocClient;
  public MyLocationListenner myListener = new MyLocationListenner();
  BitmapDescriptor mCurrentMarker;

  GeoCoder mSearch = null; // 搜索模块,因为百度定位sdk能够得到经纬度,但是却无法得到具体的详细地址,因此需要采取反编码方式去搜索此经纬度代表的地址
  private BaiduReceiver mReceiver; // 注册广播接收器,用于监听网络以及验证key
  static BDLocation lastLocation = null;

  private BitmapDescriptor bdgeo =
      BitmapDescriptorFactory.fromResource(R.drawable.icon_geo); // 当前位置的显示图标

  @Override
  protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.activity_location);
    initBaiduMap();
  }

  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);
  }

  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);
    }
  }

  private void goToChatPage() {
    if (lastLocation != null) {
      Intent intent = new Intent();
      intent.putExtra("y", lastLocation.getLongitude()); // ����
      intent.putExtra("x", lastLocation.getLatitude()); // ��
      intent.putExtra("address", lastLocation.getAddrStr());
      setResult(RESULT_OK, intent);
      this.finish();
    } else {
      showToast("位置为空!");
    }
  }

  /** 定位SDK监听函数 */
  public class MyLocationListenner implements BDLocationListener {

    @Override
    public void onReceiveLocation(BDLocation location) {
      // map view 销毁后不在处理新接收的位置
      if (location == null || mMapView == null) return;

      if (lastLocation != null) {
        if (lastLocation.getLatitude() == location.getLatitude()
            && lastLocation.getLongitude() == location.getLongitude()) {
          BmobLog.i("获取坐标相同"); // 若两次请求获取到的地理位置坐标是相同的,则不再定位
          mLocClient.stop();
          return;
        }
      }
      lastLocation = location;
      // TODO 测试上传位置!
      CustomApplication.getInstance().mLastLocation =
          new BmobGeoPoint(location.getLongitude(), location.getLatitude());
      updateUserLocation();

      BmobLog.i(
          "lontitude = "
              + location.getLongitude()
              + ",latitude = "
              + location.getLatitude()
              + ",地址 = "
              + lastLocation.getAddrStr());

      //			MyLocationData locData = new MyLocationData.Builder()
      //					.accuracy(location.getRadius())
      //					// 此处设置开发者获取到的方向信息,顺时针0-360
      //					.direction(100).latitude(location.getLatitude())
      //					.longitude(location.getLongitude()).build();
      //			mBaiduMap.setMyLocationData(locData);
      //			LatLng ll = new LatLng(location.getLatitude(),
      //					location.getLongitude());
      //			String address = location.getAddrStr();
      //			if (address != null && !address.equals("")) {
      //				lastLocation.setAddrStr(address);
      //			} else {
      //				// 反Geo搜索
      //				mSearch.reverseGeoCode(new ReverseGeoCodeOption().location(ll));
      //			}
      // TODO 显示在地图上
      //			MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
      //			mBaiduMap.animateMapStatus(u);
      // 设置按钮可点击
      mHeadLayout.getRightImageButton().setEnabled(true);
    }
  }

  public class BaiduReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
      String s = intent.getAction();
      if (s.equals(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR)) {
        showToast("key 验证出错! 请在 AndroidManifest.xml 文件中检查 key 设置");
      } else if (s.equals(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR)) {
        showToast("当前网络连接不稳定,请检查您的网络设置!");
      }
    }
  }

  @Override
  public void onGetGeoCodeResult(GeoCodeResult arg0) {}

  @Override
  public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
    if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
      showToast("抱歉,未能找到结果");
      return;
    }
    BmobLog.i("反编码得到的地址:" + result.getAddress());
    lastLocation.setAddrStr(result.getAddress());
  }

  @Override
  protected void onPause() {
    super.onPause();
    mMapView.onPause();
    lastLocation = null;
  }

  @Override
  protected void onResume() {
    super.onResume();
    mMapView.onResume();
  }

  @Override
  protected void onDestroy() {
    if (mLocClient != null && mLocClient.isStarted()) {
      // 退出时销毁定位
      mLocClient.stop();
    }
    // 关闭定位图层
    mBaiduMap.setMyLocationEnabled(false);
    mMapView.onDestroy();
    mMapView = null;
    // 取消监听 SDK 广播
    unregisterReceiver(mReceiver);
    super.onDestroy();
    // 回收 bitmap 资源
    bdgeo.recycle();
  }
}
Ejemplo n.º 24
0
 private void markFirstLocation() {
   LatLng latLng = new LatLng(firstLocationLatitude, firstLocationLongitude);
   BitmapDescriptor markBitmap = BitmapDescriptorFactory.fromResource(R.drawable.lbxz);
   OverlayOptions overlayOptions = new MarkerOptions().position(latLng).icon(markBitmap);
   baiduMap.addOverlay(overlayOptions);
 }
Ejemplo n.º 25
0
 // 覆盖物初始化
 private void initMapWu() {
   // TODO Auto-generated method stub
   mMarker = BitmapDescriptorFactory.fromResource(R.drawable.dingweitubiao); // 获得定位的图片
 }
Ejemplo n.º 26
0
 private void markClickLocation(LatLng latLng) {
   baiduMap.clear();
   BitmapDescriptor markBitmap = BitmapDescriptorFactory.fromResource(R.drawable.djwz);
   OverlayOptions overlayOptions = new MarkerOptions().position(latLng).icon(markBitmap);
   baiduMap.addOverlay(overlayOptions);
 }
Ejemplo n.º 27
0
  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 initMarker() {
   // TODO Auto-generated method stub
   mMarker = BitmapDescriptorFactory.fromResource(R.drawable.maker);
   mMarkerLy = (RelativeLayout) findViewById(R.id.id_maker_ly);
 }
Ejemplo n.º 29
0
public class LocationActivity extends BaseActivity implements OnGetGeoCoderResultListener {
  public static final int SEND = 0;
  public static final String TYPE = "type";
  public static final String TYPE_SELECT = "select";
  public static final String LATITUDE = "latitude";
  public static final String LONGITUDE = "longitude";
  public static final String TYPE_SCAN = "scan";
  public static final String ADDRESS = "address";
  private static BDLocation lastLocation = null;
  private LocationClient locClient;
  private MyLocationListener myListener = new MyLocationListener();
  private MapView mapView;
  private BaiduMap baiduMap;
  private BaiduReceiver receiver;
  private GeoCoder geoCoder = null;
  private BitmapDescriptor descriptor =
      BitmapDescriptorFactory.fromResource(R.drawable.chat_location_activity_icon_geo);
  private String intentType;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chat_location_activity);
    initBaiduMap();
  }

  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 boolean onCreateOptionsMenu(Menu menu) {
    if (intentType != null && intentType.equals(TYPE_SELECT)) {
      MenuItem add = menu.add(0, SEND, 0, R.string.chat_location_activity_send);
      alwaysShowMenuItem(add);
    }
    return super.onCreateOptionsMenu(menu);
  }

  @Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
    int id = item.getItemId();
    if (id == SEND) {
      gotoChatPage();
    }
    return super.onMenuItemSelected(featureId, item);
  }

  private void gotoChatPage() {
    if (lastLocation != null) {
      Intent intent = new Intent();
      intent.putExtra(LATITUDE, lastLocation.getLatitude()); // 经度
      intent.putExtra(LONGITUDE, lastLocation.getLongitude()); // 维度
      intent.putExtra(ADDRESS, lastLocation.getAddrStr());
      setResult(RESULT_OK, intent);
      this.finish();
    } else {
      toast(R.string.chat_getGeoInfoFailed);
    }
  }

  @Override
  public void onGetGeoCodeResult(GeoCodeResult arg0) {
    // TODO Auto-generated method stub
  }

  @Override
  public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
    // TODO Auto-generated method stub
    if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
      toast(getString(R.string.chat_cannotFindResult));
      return;
    }
    Logger.d(getString(R.string.chat_reverseGeoCodeResultIs) + result.getAddress());
    lastLocation.setAddrStr(result.getAddress());
  }

  @Override
  protected void onPause() {
    mapView.onPause();
    super.onPause();
    lastLocation = null;
  }

  @Override
  protected void onResume() {
    mapView.onResume();
    super.onResume();
  }

  @Override
  protected void onDestroy() {
    if (locClient != null && locClient.isStarted()) {
      // 退出时销毁定位
      locClient.stop();
    }
    // 关闭定位图层
    baiduMap.setMyLocationEnabled(false);
    mapView.onDestroy();
    mapView = null;
    // 取消监听 SDK 广播
    unregisterReceiver(receiver);
    super.onDestroy();
    // 回收 bitmap 资源
    descriptor.recycle();
  }

  public static void startToSeeLocationDetail(Context ctx, double latitude, double longitude) {
    Intent intent = new Intent(ctx, LocationActivity.class);
    intent.putExtra(LocationActivity.TYPE, LocationActivity.TYPE_SCAN);
    intent.putExtra(LocationActivity.LATITUDE, latitude);
    intent.putExtra(LocationActivity.LONGITUDE, longitude);
    ctx.startActivity(intent);
  }

  public static void startToSelectLocationForResult(Activity from, int requestCode) {
    Intent intent = new Intent(from, LocationActivity.class);
    intent.putExtra(LocationActivity.TYPE, LocationActivity.TYPE_SELECT);
    from.startActivityForResult(intent, requestCode);
  }

  /** 定位SDK监听函数 */
  public class MyLocationListener implements BDLocationListener {

    @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);
      // 设置按钮可点击
    }
  }

  /** 构造广播监听类,监听 SDK key 验证以及网络异常广播 */
  public class BaiduReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
      String s = intent.getAction();
      if (s.equals(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR)) {
        toast(getString(R.string.chat_location_mapKeyErrorTips));
      } else if (s.equals(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR)) {
        toast(getString(R.string.chat_pleaseCheckNetwork));
      }
    }
  }
}
Ejemplo n.º 30
0
public class WMapFjyhView extends BaseLayout {

  private MapView mMapView;
  private BaiduMap mBaiduMap;
  private LocationClient mLocClient;
  private Context context;
  boolean isFirstLoc = true; // 是否首次定位
  List<Marker> markers = new ArrayList<Marker>();
  public MyLocationListenner myListener = new MyLocationListenner();
  BitmapDescriptor bdA = BitmapDescriptorFactory.fromResource(R.drawable.icon_marka);

  public WMapFjyhView(Context context) {
    super(context, R.layout.w_map_fjyh);
    // TODO Auto-generated constructor stub
    this.context = context;

    this.InitMapView();
  }

  /** 定位SDK监听函数 */
  public class MyLocationListenner implements BDLocationListener {

    @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;
        LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        mBaiduMap.animateMapStatus(u);
      }
    }

    public void onReceivePoi(BDLocation poiLocation) {}
  }

  private void InitMapView() {
    // 地图初始化
    mMapView = (MapView) findViewById(R.id.bmapView);
    mBaiduMap = mMapView.getMap();
    // 开启定位图层
    mBaiduMap.setMyLocationEnabled(true);
    // 定位初始化
    mLocClient = new LocationClient(this.context);
    mLocClient.registerLocationListener(myListener);
    LocationClientOption option = new LocationClientOption();
    option.setOpenGps(true); // 打开gps
    option.setCoorType("bd09ll"); // 设置坐标类型
    option.setScanSpan(1000);
    mLocClient.setLocOption(option);
    mLocClient.start();

    this.drawPoints();
  }

  public void onPause() {
    mMapView.onPause();
  }

  public void onResume() {
    mMapView.onResume();
  }

  public void onDestroy() {
    // 退出时销毁定位
    mLocClient.stop();
    // 关闭定位图层
    mBaiduMap.setMyLocationEnabled(false);
    mMapView.onDestroy();
    mMapView = null;
    super.onDestroy();
  }

  public void drawPoints() {
    mBaiduMap.clear();
    // List<FavoritePoiInfo> list = FavoriteManager.getInstance().getAllFavPois();
    /*if (list == null || list.size() == 0) {
    	Toast.makeText(this.context, "没有收藏点", Toast.LENGTH_LONG)
    	.show();
    	return;
    }*/
    Random rad = new Random();
    LocationInfo currPoint = ((ZsyyApplication) this.context.getApplicationContext()).currPoint;
    List<LatLng> list = new ArrayList<LatLng>();
    int[] arr = new int[] {1, -1};
    if (currPoint != null) {
      for (int i = 0; i < 10; i++) {
        double lau = currPoint.getLatitude() + (rad.nextDouble() / 20) * arr[i % 2];
        double lag = currPoint.getLontitude() + (rad.nextDouble() / 20) * arr[i % 2];
        LatLng p1 = new LatLng(lau, lag);
        list.add(p1);
      }
    }
    if (list.size() < 1) {
      return;
    }

    /*		LatLng p1 = new LatLng(31.257023, 121.564404);
    LatLng p2 = new LatLng(31.257023, 121.507428);
    LatLng p3 = new LatLng(31.257023, 121.597428);
    list.add(p1);
    list.add(p2);
    list.add(p3);*/
    // 绘制在地图
    markers.clear();
    for (int i = 0; i < list.size(); i++) {
      MarkerOptions option = new MarkerOptions().icon(bdA).position(list.get(i));
      /*Bundle b = new Bundle();
      b.putString("id", list.get(i).getID());
      option.extraInfo(b);*/
      markers.add((Marker) mBaiduMap.addOverlay(option));
    }
  }
}