@Override
  public void init() {
    // 设置是否显示比例尺控件
    mapView.showScaleControl(true);
    // 设置是否显示缩放控件
    mapView.showZoomControls(false);
    baiduMap = mapView.getMap();
    // 设置监听
    baiduMap.setOnMapClickListener(
        new OnMapClickListener() {
          @Override
          public boolean onMapPoiClick(MapPoi mapPoi) {
            return false;
          }

          @Override
          public void onMapClick(final LatLng latLng) {
            System.out.println(latLng.latitude + "--" + latLng.longitude);
            geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(latLng));
            showWaiting(true);
            ok.setEnabled(false);
            markFirstLocation();
            markClickLocation(latLng);
          }
        });
    // 检索
    geoCoder = GeoCoder.newInstance();
    geoCoder.setOnGetGeoCodeResultListener(getGeoCoderResultListener);
    // 开始定位
    client = new LocationClient(getApplicationContext());
    client.setLocOption(getDefaultLocationClientOption());
    client.registerLocationListener(dbListener);
    client.start();
    // waiting的layout的初始化
    waitingAnimation =
        AnimationUtils.loadAnimation(SelectLocationActivity.this, R.anim.anim_waiting);
    waitingIcon.setAnimation(waitingAnimation);
    showWaiting(true);
    // 位置列表初始化
    adapter = new LocationAdapter();
    locationListView.setAdapter(adapter);
    locationListView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            locationList.get(currentLocation).setSelected(false);
            locationList.get(position).setSelected(true);
            currentLocation = position;
            adapter.notifyDataSetChanged();
            // 重置标志
            markFirstLocation();
            markClickLocation(locationList.get(position).getLatLng());
          }
        });
    // 按钮
    back.setOnClickListener(clickListener);
    ok.setOnClickListener(clickListener);
    ok.setEnabled(false);
    Log.e("tag", "---------------------create---------------------------");
  }
Пример #2
0
 /**
  * 从view 得到图片
  *
  * @param view
  * @return
  */
 public BMapUtil(Activity context) {
   try {
     mContext = context;
     mSearch = GeoCoder.newInstance();
     mSearch.setOnGetGeoCodeResultListener(this);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  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);
    }
  }
Пример #4
0
  @Override
  public boolean onMarkerClick(final Marker marker) {
    if (marker != null) {
      final LatLng latLng = marker.getPosition();
      if (latLng != null && mGeoCoder == null) {
        final ReverseGeoCodeOption reverseGeoCodeOption = new ReverseGeoCodeOption();
        reverseGeoCodeOption.location(latLng);

        mGeoCoder = GeoCoder.newInstance();
        mGeoCoder.setOnGetGeoCodeResultListener(this);
        if (!mGeoCoder.reverseGeoCode(reverseGeoCodeOption)) mGeoCoder = null;
      }
    }

    return false;
  }
Пример #5
0
  private void initview() {
    outmap = (ImageView) findViewById(R.id.outmap);
    back = (LinearLayout) findViewById(R.id.map2_back);
    mylocation = (ImageView) findViewById(R.id.mylocation);
    mMapView = (MapView) findViewById(R.id.map2);
    mBaiduMap = mMapView.getMap();
    // 初始化搜索模块,注册事件监听
    msearch2 = GeoCoder.newInstance();
    msearch2.setOnGetGeoCodeResultListener(this);

    outmap.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            showPopupWindow(-126, 24);
          }
        });

    back.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            finish();
          }
        });
    mylocation.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            CenterToMyLocation();
          }
        });
    data = new ArrayList<Map<String, Object>>();
    Map<String, Object> map = new HashMap<>();
    map.put("name", "百度地图");
    data.add(map);
    Map<String, Object> map2 = new HashMap<>();
    map2.put("name", "高德地图");
    data.add(map2);
  }
Пример #6
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);
  }