コード例 #1
0
  /** 实现左右滑动切换校区 */
  @Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    float zoom = 17;
    if (e1.getX() - e2.getX() > 100) {
      if (flag < position_schoolLatLngs.length - 1) {
        flag++;
      } else {
        flag = 0;
      }
      this.flipper.setInAnimation(
          AnimationUtils.loadAnimation(this.getActivity(), R.anim.push_left_in));
      this.flipper.setOutAnimation(
          AnimationUtils.loadAnimation(this.getActivity(), R.anim.push_left_out));
    } else if (e1.getX() - e2.getX() < -100) {
      if (flag > 0) {
        flag--;
      } else {
        flag = position_schoolLatLngs.length - 1;
      }
      this.flipper.setInAnimation(
          AnimationUtils.loadAnimation(this.getActivity(), R.anim.push_right_in));
      this.flipper.setOutAnimation(
          AnimationUtils.loadAnimation(this.getActivity(), R.anim.push_right_out));
    }
    mMap.clear();
    loadMap(flag + 2, true);
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position_schoolLatLngs[flag], zoom));
    this.flipper.setDisplayedChild(flag);

    return false;
  }
コード例 #2
0
  /** 判断当前位置位于哪个校区 */
  private void judge_position() {
    if (mLocation.getLatitude() < 36.648152
        && mLocation.getLongitude() > 117.068195
        && mLocation.getLatitude() > 36.642666
        && mLocation.getLongitude() < 117.080217) {

      flag = 2; // 燕山校区
    } else if (mLocation.getLatitude() < 36.66187
        && mLocation.getLongitude() > 117.501132
        && mLocation.getLatitude() > 36.651857
        && mLocation.getLongitude() < 117.520319) {
      flag = 0; // 明水校区
    } else if (mLocation.getLatitude() < 36.674867
        && mLocation.getLongitude() > 117.370944
        && mLocation.getLatitude() > 36.665148
        && mLocation.getLongitude() < 117.380147) {
      flag = 1; // 圣井校区
    } else if (mLocation.getLatitude() < 36.631209
        && mLocation.getLongitude() > 117.019616
        && mLocation.getLatitude() > 36.619802
        && mLocation.getLongitude() < 117.026629) {
      flag = 3; // 舜耕校区
    }
    mMap.clear();
    this.flipper.setDisplayedChild(flag);
    mMap.animateCamera(
        CameraUpdateFactory.newLatLngZoom(position_schoolLatLngs[flag], zoom_current));
    startTextView.setText(null);
    endTextView.setText(null);
    isClickStart = true;
    isClickTarget = false;
    loadMap(flag + 2, true);
  }
コード例 #3
0
  /** POI信息查询回调方法 */
  @Override
  public void onPoiSearched(PoiResult result, int rCode) {
    dissmissProgressDialog(); // 隐藏对话框
    if (rCode == 0) {
      if (result != null && result.getQuery() != null) { // 搜索poi的结果
        if (result.getQuery().equals(query)) { // 是否是同一条
          poiResult = result;
          // 取得搜索到的poiitems有多少页
          List<PoiItem> poiItems = poiResult.getPois(); // 取得第一页的poiitem数据,页数从数字0开始
          List<SuggestionCity> suggestionCities =
              poiResult.getSearchSuggestionCitys(); // 当搜索不到poiitem数据时,会返回含有搜索关键字的城市信息

          if (poiItems != null && poiItems.size() > 0) {
            aMap.clear(); // 清理之前的图标
            PoiOverlay poiOverlay = new PoiOverlay(aMap, poiItems);
            poiOverlay.removeFromMap();
            poiOverlay.addToMap();
            poiOverlay.zoomToSpan();
          } else if (suggestionCities != null && suggestionCities.size() > 0) {
            showSuggestCity(suggestionCities);
          } else {
            ToastUtil.show(PoiKeywordSearchActivity.this, "no_result");
          }
        }
      } else {
        ToastUtil.show(PoiKeywordSearchActivity.this, "no_result");
      }
    } else if (rCode == 27) {
      ToastUtil.show(PoiKeywordSearchActivity.this, "error_network");
    } else if (rCode == 32) {
      ToastUtil.show(PoiKeywordSearchActivity.this, "验证无效");
    } else {
      ToastUtil.show(PoiKeywordSearchActivity.this, "未知错误" + rCode);
    }
  }
コード例 #4
0
 public void clear() {
   if (aMap != null) {
     aMap.clear();
     markerMgr.clearAll();
     overlayMgr.clearAll();
   }
 }
コード例 #5
0
 /** 单击下方ViewFlipper回到校区中心点 */
 @Override
 public boolean onSingleTapUp(MotionEvent e) {
   mMap.clear();
   startTextView.setText(null);
   endTextView.setText(null);
   mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position_schoolLatLngs[flag], 17));
   isClickStart = true;
   isClickTarget = false;
   loadMap(flag + 2, true);
   return true;
 }
コード例 #6
0
 /** 方法必须重写 */
 @Override
 protected void onDestroy() {
   if (aMap != null) {
     aMap.clear();
   }
   overlayMgr.clean();
   markerMgr.clearAll();
   stopLocation();
   super.onDestroy();
   mapView.onDestroy();
 }
コード例 #7
0
 @Override
 public void onPoiSearched(PoiResult poiResult, int errorCode) {
   if (mListener != null) {
     mListener.cbPoiSearch(poiResult, errorCode);
   }
   if (errorCode == 0 && poiResult != null && isShowOverlay && aMap != null) {
     ArrayList<PoiItem> poiItems = poiResult.getPois();
     // 当搜索不到poiitem数据时,会返回含有搜索关键字的城市信息
     if (poiItems != null && poiItems.size() > 0) {
       aMap.clear(); // 清理之前的图标
       PoiOverlay poiOverlay = new PoiOverlay(aMap, poiItems);
       poiOverlay.removeFromMap();
       poiOverlay.addToMap();
       poiOverlay.zoomToSpan();
       isShowOverlay = false;
     }
   }
 }
コード例 #8
0
ファイル: MainActivity.java プロジェクト: caocf/yunt
  /** 获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker */
  private void resetMarks() {
    // 开始刷新界面
    Projection projection = aMap.getProjection();
    Point p = null;
    markerOptionsListInView.clear();
    // 获取在当前视野内的marker;提高效率
    for (MarkerOptions mp : markerOptionsList) {
      p = projection.toScreenLocation(mp.getPosition());
      if (p.x < 0 || p.y < 0 || p.x > width || p.y > height) {
        // 不添加到计算的列表中
      } else {
        markerOptionsListInView.add(mp);
      }
    }
    // 自定义的聚合类MarkerCluster
    ArrayList<MarkerCluster> clustersMarker = new ArrayList<MarkerCluster>();
    for (MarkerOptions mp : markerOptionsListInView) {
      if (clustersMarker.size() == 0) {
        clustersMarker.add(
            new MarkerCluster(MainActivity.this, mp, projection, gridSize)); // 100根据自己需求调整
      } else {
        boolean isIn = false;
        for (MarkerCluster cluster : clustersMarker) {
          if (cluster.getBounds().contains(mp.getPosition())) {
            cluster.addMarker(mp);
            isIn = true;
            break;
          }
        }
        if (!isIn) {
          clustersMarker.add(new MarkerCluster(MainActivity.this, mp, projection, gridSize));
        }
      }
    }

    // 先清除地图上所有覆盖物
    aMap.clear();
    for (MarkerCluster markerCluster : clustersMarker) {
      markerCluster.setpositionAndIcon(); // 设置聚合点的位置和icon
      aMap.addMarker(markerCluster.getOptions()); // 重新添加
    }
  }
コード例 #9
0
 @Override
 public void onWalkRouteSearched(WalkRouteResult result, int rCode) {
   progDialog.dismiss();
   if (rCode == 0) {
     if (result != null && result.getPaths() != null && result.getPaths().size() > 0) {
       walkRouteResult = result;
       WalkPath walkPath = walkRouteResult.getPaths().get(0);
       mMap.clear(); // 清理地图上的所有覆盖物
       MyWalkRouteOverlay walkRouteOverlay =
           new MyWalkRouteOverlay(
               getActivity(),
               mMap,
               walkPath,
               walkRouteResult.getStartPos(),
               walkRouteResult.getTargetPos(),
               startTextView.getText().toString(),
               endTextView.getText().toString());
       walkRouteOverlay.removeFromMap();
       walkRouteOverlay.addToMap();
       walkRouteOverlay.zoomToSpan();
       loadMap(flag + 2, false);
     }
   }
 }
コード例 #10
0
 /** 清空地图上所有已经标注的marker */
 public void onClearMap(AMap amap) {
   if (AMapUtil.checkReady(context, amap)) {
     amap.clear();
   }
 }