/** 实现左右滑动切换校区 */
  @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;
  }
  /** 判断当前位置位于哪个校区 */
  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
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(EUExUtil.getResLayoutID("plugin_uexgaodemap_basic_layout"));
    /*
     * 设置离线地图存储目录,在下载离线地图或初始化地图设置;
     * 使用过程中可自行设置, 若自行设置了离线地图存储的路径,
     * 则需要在离线地图下载和使用地图页面都进行路径设置
     * */
    // Demo中为了其他界面可以使用下载的离线地图,使用默认位置存储,屏蔽了自定义设置
    //  MapsInitializer.sdcardDir =OffLineMapUtils.getSdCacheDir(this);
    Intent intent = getIntent();
    mListener = (OnCallBackListener) intent.getSerializableExtra("callback");

    mContent = (FrameLayout) findViewById(EUExUtil.getResIdID("plugin_uexgaodemap_bg_content"));
    mButtons = new HashMap<String, CustomButtonBean>();
    mapView = (MapView) findViewById(EUExUtil.getResIdID("plugin_uexgaodemap_basic_map"));
    mapView.onCreate(savedInstanceState); // 此方法必须重写
    init();
    aMap.setOnMapLoadedListener(this);
    aMap.setOnMapClickListener(this);
    aMap.setOnMapLongClickListener(this);
    mCenter = intent.getDoubleArrayExtra(JsConst.LATLNG);
    markerMgr = new GaodeMapMarkerMgr(this, aMap, mListener, mOverlays);
    overlayMgr = new GaodeMapOverlayMgr(this, aMap, mListener, mOverlays);
    aMap.setOnMarkerClickListener(markerMgr);
    aMap.setOnInfoWindowClickListener(markerMgr);
  }
 /** 建立地图 */
 private void setUpMap() {
   aMap.setLocationSource(this); // 设置定位监听
   aMap.getUiSettings().setMyLocationButtonEnabled(true); // 设置默认定位按钮是否显示
   aMap.setMyLocationEnabled(true); // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
   // 设置定位的类型为定位模式:定位(AMap.LOCATION_TYPE_LOCATE)、跟随(AMap.LOCATION_TYPE_MAP_FOLLOW)
   // 地图根据面向方向旋转(AMap.LOCATION_TYPE_MAP_ROTATE)三种模式
   aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
 }
Пример #5
0
 /** @param level value range 3~20 */
 public void setZoomLevel(float level) {
   if (aMap != null) {
     if (level < aMap.getMinZoomLevel()) {
       level = aMap.getMinZoomLevel();
     } else if (level > aMap.getMaxZoomLevel()) {
       level = aMap.getMaxZoomLevel();
     }
     aMap.moveCamera(CameraUpdateFactory.zoomTo(level));
   }
 }
Пример #6
0
 public void setMarkerVisibleBounds(VisibleBoundsVO data) {
   List<Marker> list = aMap.getMapScreenMarkers();
   if (list != null && list.size() > 0) {
     LatLngBounds.Builder builder = LatLngBounds.builder();
     for (int i = 0; i < list.size(); i++) {
       LatLng item = list.get(i).getPosition();
       builder.include(item);
     }
     aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), data.getPadding()));
   }
 }
 /** 单击下方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;
 }
 /** 设置页面监听 */
 private void setUpMap() {
   Button searButton = (Button) findViewById(R.id.searchButton);
   searButton.setOnClickListener(this);
   Button nextButton = (Button) findViewById(R.id.nextButton);
   nextButton.setOnClickListener(this);
   searchText = (AutoCompleteTextView) findViewById(R.id.keyWord);
   searchText.addTextChangedListener(this); // 添加文本输入框监听事件
   editCity = (EditText) findViewById(R.id.city);
   aMap.setOnMarkerClickListener(this); // 添加点击marker监听事件
   aMap.setInfoWindowAdapter(this); // 添加显示infowindow监听事件
 }
 /** 设置定位相关 */
 private void setLocation() {
   // 自定义系统定位小蓝点
   MyLocationStyle myLocationStyle = new MyLocationStyle();
   myLocationStyle.myLocationIcon(
       BitmapDescriptorFactory.fromResource(R.drawable.location_marker));
   myLocationStyle.strokeColor(Color.BLACK);
   myLocationStyle.radiusFillColor(Color.alpha(0));
   myLocationStyle.strokeWidth(1);
   mMap.setMyLocationStyle(myLocationStyle);
   mAMapLocationManager = LocationManagerProxy.getInstance(getActivity());
   mMap.setLocationSource(this);
 }
Пример #10
0
 /** 初始化AMap对象 */
 private void init() {
   if (aMap == null) {
     aMap = mapView.getMap();
   }
   if (settings == null) {
     settings = aMap.getUiSettings();
   }
   if (mOverlays == null) {
     mOverlays = new ArrayList<LatLng>();
   }
   aMap.setLocationSource(this);
 }
Пример #11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_discover);
    mapView = (MapView) findViewById(R.id.map);
    mapView.onCreate(savedInstanceState);

    mark = new MarkerOptions[5];
    LatLng lat[] = new LatLng[5];
    lat[0] = new LatLng(31.2901513159, 120.5917328110);
    lat[1] = new LatLng(31.28015100, 120.59731000);
    lat[2] = new LatLng(31.180111000, 120.1232322);
    lat[3] = new LatLng(32.23123213, 121.32132);
    lat[4] = new LatLng(29.321321, 11.32123321);

    init();

    for (int i = 0; i < 5; i++) {
      mark[i] = new MarkerOptions();
      mark[i].position(lat[i]);
      mark[i].title("SBicycle store").snippet("the first SBicycle store in suzhou");
      mark[i].icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_bicycle));
      Marker marker = aMap.addMarker(mark[i]);
    }
  }
  /** 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);
    }
  }
Пример #13
0
 public void clear() {
   if (aMap != null) {
     aMap.clear();
     markerMgr.clearAll();
     overlayMgr.clearAll();
   }
 }
 @Override
 public void onMapLoaded() {
   uiSettings = mMap.getUiSettings();
   uiSettings.setZoomControlsEnabled(false);
   uiSettings.setMyLocationButtonEnabled(true);
   loadMap(Constants.MapId_Mingshui, true);
 }
 private void addPolyLine(PolylineOptions options) {
   if (options == null) {
     return;
   }
   Polyline polyline = mAMap.addPolyline(options);
   if (polyline != null) {
     allPolyLines.add(polyline);
   }
 }
 /** 定位成功后回调函数 */
 @Override
 public void onLocationChanged(AMapLocation aLocation) {
   if (mListener != null) {
     zoom_current = mMap.getCameraPosition().zoom;
     mListener.onLocationChanged(aLocation);
     mLocation = aLocation;
     judge_position();
     deactivate();
   }
 }
Пример #17
0
 public void setOverlayVisibleBounds(VisibleBoundsVO data) {
   if (mOverlays != null && mOverlays.size() > 0) {
     LatLngBounds.Builder builder = LatLngBounds.builder();
     for (int i = 0; i < mOverlays.size(); i++) {
       LatLng item = mOverlays.get(i);
       builder.include(item);
     }
     aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), data.getPadding()));
   }
 }
Пример #18
0
  /** 获取视野内的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()); // 重新添加
    }
  }
 /**
  * 移动镜头到当前的视角。
  *
  * @since V2.1.0
  */
 public void zoomToSpan() {
   if (startPoint != null) {
     if (mAMap == null) return;
     try {
       LatLngBounds bounds = getLatLngBounds();
       mAMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
     } catch (Throwable e) {
       e.printStackTrace();
     }
   }
 }
Пример #20
0
 /** 方法必须重写 */
 @Override
 protected void onDestroy() {
   if (aMap != null) {
     aMap.clear();
   }
   overlayMgr.clean();
   markerMgr.clearAll();
   stopLocation();
   super.onDestroy();
   mapView.onDestroy();
 }
 @Override
 public void onCameraChangeFinish(CameraPosition arg0) {
   zoom_current = mMap.getCameraPosition().zoom;
   Log.i("zoom", "" + zoom_current);
   if (zoom_current < 17 && getMapPoints != null && !isDestroy) {
     changeMarkerToRedPoint(getMapPoints);
     isDestroy = true;
   } else if (zoom_current >= 17 && isDestroy) {
     getMapPoints.addMarkers();
     isDestroy = false;
   }
   Log.i("isDestroy", "" + isDestroy);
 }
Пример #22
0
  private void setUpMap() {
    aMap.setLocationSource(this);
    aMap.setOnMarkerClickListener(this);
    aMap.setOnInfoWindowClickListener(this);
    aMap.getUiSettings().setMyLocationButtonEnabled(true);
    aMap.setMyLocationEnabled(true);

    aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
  }
Пример #23
0
  private void addMarkers(ArrayList<HashMap<String, String>> data) {

    for (int i = 0; i < data.size(); i++) {
      double Position_x = Double.parseDouble(data.get(i).get("POSITION_X").toString());
      double Position_y = Double.parseDouble(data.get(i).get("POSITION_Y").toString());
      markerOptionsList.add(
          new MarkerOptions()
              .position(new LatLng(Position_y, Position_x))
              .title("Marker")
              .icon(BitmapDescriptorFactory.fromResource(R.drawable.ub_pick)));
    }
    aMap.addMarkers(markerOptionsList, true);
    // resetMarks();

  }
Пример #24
0
 public void setMyLocationEnable(int type) {
   Log.i(TAG, "setMyLocationEnable-type = " + type);
   if (aMap != null) {
     aMap.setMyLocationEnabled(type == JsConst.ENABLE);
     if (type == JsConst.ENABLE) {
       if (mLocationListener == null) {
         mLocationListener = new GaodeLocationListener();
       }
       if (mLocationListener.getType() != JsConst.CONTINUED) {
         if (mLocationMgr == null) mLocationMgr = LocationManagerProxy.getInstance(this);
         mLocationListener.setType(JsConst.SHOW_LOCATION);
         mLocationMgr.requestLocationData(
             LocationProviderProxy.AMapNetwork, -1, 0, mLocationListener);
       }
     }
   }
 }
Пример #25
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;
     }
   }
 }
Пример #26
0
  private void setUpMap() {
    aMap.setOnMarkerClickListener(this);
    aMap.setOnCameraChangeListener(this);

    // 自定义系统定位蓝点
    MyLocationStyle myLocationStyle = new MyLocationStyle();

    // 设置定位图标围栏为透明
    myLocationStyle.radiusFillColor(color.transparent);

    // 自定义定位蓝点图标
    myLocationStyle.myLocationIcon(
        BitmapDescriptorFactory.fromResource(R.drawable.md_switch_thumb_on_pressed));

    // 自定义精度范围的圆形边框颜色
    myLocationStyle.strokeColor(Color.TRANSPARENT);

    // 自定义精度范围的圆形边框宽度
    myLocationStyle.strokeWidth(0);

    // 将自定义的 myLocationStyle 对象添加到地图上
    aMap.setMyLocationStyle(myLocationStyle);

    // 设置定位监听
    aMap.setLocationSource(this);

    // 设置默认定位按钮是否显示
    aMap.getUiSettings().setMyLocationButtonEnabled(true);
    aMap.getUiSettings().setZoomControlsEnabled(false);
    aMap.getUiSettings().setMyLocationButtonEnabled(false);

    // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
    aMap.setMyLocationEnabled(true);

    // 设置定位的类型为定位模式:定位(AMap.LOCATION_TYPE_LOCATE)、跟随(AMap.LOCATION_TYPE_MAP_FOLLOW)
    // 地图根据面向方向旋转(AMap.LOCATION_TYPE_MAP_ROTATE)三种模式
    aMap.setMyLocationType(AMap.LOCATION_TYPE_MAP_FOLLOW);
  }
  /** 设置地图 */
  private void setUpMap() {
    mMap.setOnMarkerClickListener(this); // 设置点击marker事件监听器
    mMap.setInfoWindowAdapter(this);
    mMap.setOnInfoWindowClickListener(this); // 设置点击infoWindow事件监听器
    mMap.setOnMapLoadedListener(this); // 设置map载入成功事件监听器
    mMap.setOnCameraChangeListener(this);
    routeSearch = new RouteSearch(getActivity());
    routeSearch.setRouteSearchListener(this);
    setLocation();
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position_schoolLatLngs[0], 17.904732f));
    startTextView =
        (AutoCompleteTextView) schoolView.findViewById(R.id.autotextview_roadsearch_start);
    startTextView.setFocusable(false);
    endTextView =
        (AutoCompleteTextView) schoolView.findViewById(R.id.autotextview_roadsearch_goals);
    endTextView.setFocusable(false);
    routeSearchImagebtn = (ImageButton) schoolView.findViewById(R.id.imagebtn_roadsearch_search);
    routeSearchImagebtn.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            strStart = startTextView.getText().toString().trim();
            strEnd = endTextView.getText().toString().trim();
            if (strStart == null || strStart.length() == 0) {
              Toast.makeText(getActivity(), "请选择起点", Toast.LENGTH_SHORT).show();
              return;
            }
            if (strEnd == null || strEnd.length() == 0) {
              Toast.makeText(getActivity(), "请选择终点", Toast.LENGTH_SHORT).show();
              return;
            }
            if (startPoint != null && endPoint != null) {
              if (NetworkUtils.isConnect(getActivity())) {
                progDialog = ProgressDialog.show(getActivity(), null, "正在搜索", true, true);
                searchRoute();
              } else {
                Toast.makeText(getActivity(), "亲,请检查网络连接", Toast.LENGTH_SHORT).show();
              }

              // searchRouteResult(startPoint, endPoint);
            }
          }
        });
  }
 @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);
     }
   }
 }
Пример #29
0
 public void dispatchMessage(android.os.Message msg) {
   try {
     jsonArray = new JSONArray(jsonResult);
     onClearMap(amap);
     for (int i = 0; i < jsonArray.length(); i++) {
       LatLng startpt =
           new LatLng(
               StringToDouble(jsonArray.getJSONObject(i).getString("LAT")),
               StringToDouble(jsonArray.getJSONObject(i).getString("LONG1"))); // 创建一个点对象
       amap.addMarker(
           new MarkerOptions()
               .title("公司名称 :" + jsonArray.getJSONObject(i).getString("NAME"))
               .snippet("公司地址 :" + jsonArray.getJSONObject(i).getString("ADDRESS"))
               .position(startpt));
       sx = sy = ex = ey = 0;
       SelectionView.this.invalidate();
     }
   } catch (JSONException e) {
     sx = sy = ex = ey = 0;
     SelectionView.this.invalidate();
     Toast.makeText(context, "区域内无企业实体..", Toast.LENGTH_SHORT).show();
     e.printStackTrace();
   }
 }
Пример #30
0
 /** 清空地图上所有已经标注的marker */
 public void onClearMap(AMap amap) {
   if (AMapUtil.checkReady(context, amap)) {
     amap.clear();
   }
 }