Java Code Examples for com.amap.api.maps.AMapUtils#calculateLineDistance()

The following examples show how to use com.amap.api.maps.AMapUtils#calculateLineDistance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildingPoint.java    From RunMap with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    BuildingPoint that = (BuildingPoint) o;
    if( AMapUtils.calculateLineDistance(latLng,that.latLng) < RMConfiguration.MAX_DISTANCE){
        return true;
    }
    if(StringUtils.isEmpty(buildName) && StringUtils.isEmpty(that.buildName)){
        return false;
    }
    return buildName != null ? buildName.equals(that.buildName) : that.buildName == null;

}
 
Example 2
Source File: GaoDeMapAiLineManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void onAiLineAddPoint(LatLng latLng, float height, float angle) {
    if (isFullSize()) {
        X8ToastUtil.showToast(this.context, this.context.getString(R.string.x8_ai_fly_lines_point_max), 0);
    } else if (this.mGaodeMapLocationManager.getHomeLocation() != null) {
        float distance = AMapUtils.calculateLineDistance(latLng, this.mGaodeMapLocationManager.getHomeLocation());
        if (10.0f > distance || distance > 1000.0f) {
            if (distance < 10.0f) {
                X8ToastUtil.showToast(this.context, String.format(this.context.getString(R.string.x8_ai_fly_follow_point_to_point_far1), new Object[]{X8NumberUtil.getDistanceNumberString(10.0f, 0, true)}), 0);
            } else if (distance > 1000.0f) {
                X8ToastUtil.showToast(this.context, String.format(this.context.getString(R.string.x8_ai_fly_follow_point_to_point_far), new Object[]{X8NumberUtil.getDistanceNumberString(1000.0f, 0, true)}), 0);
            }
        } else if (isValid(latLng)) {
            addPointLatLng(latLng, distance, this.mGaodeMapLocationManager.getDevLocation(), false, angle);
        } else {
            X8ToastUtil.showToast(this.context, String.format(this.context.getString(R.string.x8_ai_fly_lines_point_magin), new Object[]{X8NumberUtil.getDistanceNumberString(10.0f, 0, true)}), 0);
        }
    }
}
 
Example 3
Source File: SpeedAndDistanceFilter.java    From RunMap with Apache License 2.0 6 votes vote down vote up
@Override
public boolean accept(AMapLocation previous, AMapLocation current) {
    if(previous == null){
        return true;
    }
    LatLng pre = new LatLng(previous.getLatitude(), previous.getLongitude());
    LatLng cur = new LatLng(current.getLatitude(), current.getLongitude());
    float distance = AMapUtils.calculateLineDistance(pre, cur);
    if(distance < RMConfiguration.DRAW_DISTANCE){
        return false;
    }
    float speed = current.getSpeed();
    double interval = (SystemClock.elapsedRealtime() - mPreviousUpdateTime)/1000.0;
    float v = (float) (distance/interval);
    if(v > RMConfiguration.MAX_SPEED || v > speed * 1.5){
        return false;
    }
    mPreviousUpdateTime = SystemClock.elapsedRealtime();
    return true;
}
 
Example 4
Source File: MainActivity.java    From RecordPath3D with Apache License 2.0 6 votes vote down vote up
private float getDistance(List<AMapLocation> list) {
	float distance = 0;
	if (list == null || list.size() == 0) {
		return distance;
	}
	for (int i = 0; i < list.size() - 1; i++) {
		AMapLocation firstpoint = list.get(i);
		AMapLocation secondpoint = list.get(i + 1);
		LatLng firstLatLng = new LatLng(firstpoint.getLatitude(),
				firstpoint.getLongitude());
		LatLng secondLatLng = new LatLng(secondpoint.getLatitude(),
				secondpoint.getLongitude());
		double betweenDis = AMapUtils.calculateLineDistance(firstLatLng,
				secondLatLng);
		distance = (float) (distance + betweenDis);
	}
	return distance;
}
 
Example 5
Source File: AmapFragment.java    From BmapLite with Apache License 2.0 6 votes vote down vote up
public void deleteRangingPoi() {
    if (mPoiList.size() > 1) {
        MyPoiModel end = mPoiList.get(mPoiList.size() - 1);
        MyPoiModel pre = mPoiList.get(mPoiList.size() - 2);

        mTotal -= AMapUtils.calculateLineDistance(new LatLng(end.getLatitude(), end.getLongitude()),
                new LatLng(pre.getLatitude(), pre.getLongitude()));

        mPoiList.remove(mPoiList.size() - 1);
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
    } else if (mPoiList.size() == 1) {
        mPoiList.remove(mPoiList.size() - 1);
        mTotal = 0;
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
    }

    if (!mRangingMarkerList.isEmpty()) {
        mRangingMarkerList.get(mRangingMarkerList.size() - 1).remove();
        mRangingMarkerList.remove(mRangingMarkerList.size() - 1);
    }

    if (!mLineList.isEmpty()) {
        mLineList.get(mLineList.size() - 1).remove();
        mLineList.remove(mLineList.size() - 1);
    }
}
 
Example 6
Source File: AmapFragment.java    From BmapLite with Apache License 2.0 6 votes vote down vote up
private void makeMarker(MyPoiModel poi, boolean isClear) {
    if (isClear) {
        clearMarker();
    }

    int distance = 0;
    if (null != BApp.MY_LOCATION) {
        distance = (int) AMapUtils.calculateLineDistance(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude()),
                new LatLng(poi.getLatitude(), poi.getLongitude()));
    }
    Marker marker = mAmap.addMarker(new MarkerOptions().position(new LatLng(poi.getLatitude(), poi.getLongitude())).title(poi.getName()).snippet(distance + "").icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding_2)));
    markerList.add(marker);

    ((MainActivity) getActivity()).showPoiLay(poi, distance);

}
 
Example 7
Source File: AmapFragment.java    From BmapLite with GNU General Public License v3.0 6 votes vote down vote up
public void deleteRangingPoi() {
    if (mPoiList.size() > 1) {
        MyPoiModel end = mPoiList.get(mPoiList.size() - 1);
        MyPoiModel pre = mPoiList.get(mPoiList.size() - 2);

        mTotal -= AMapUtils.calculateLineDistance(new LatLng(end.getLatitude(), end.getLongitude()),
                new LatLng(pre.getLatitude(), pre.getLongitude()));

        mPoiList.remove(mPoiList.size() - 1);
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
    } else if (mPoiList.size() == 1) {
        mPoiList.remove(mPoiList.size() - 1);
        mTotal = 0;
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
    }

    if (!mRangingMarkerList.isEmpty()) {
        mRangingMarkerList.get(mRangingMarkerList.size() - 1).remove();
        mRangingMarkerList.remove(mRangingMarkerList.size() - 1);
    }

    if (!mLineList.isEmpty()) {
        mLineList.get(mLineList.size() - 1).remove();
        mLineList.remove(mLineList.size() - 1);
    }
}
 
Example 8
Source File: AmapFragment.java    From BmapLite with GNU General Public License v3.0 6 votes vote down vote up
public void setRangingPolyLine() {
    if (mPoiList.size() < 2) {
        mTotal = 0;
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
        return;
    }

    MyPoiModel end = mPoiList.get(mPoiList.size() - 1);
    MyPoiModel last = mPoiList.get(mPoiList.size() - 2);

    mTotal += AMapUtils.calculateLineDistance(new LatLng(end.getLatitude(), end.getLongitude()),
            new LatLng(last.getLatitude(), last.getLongitude()));

    List<LatLng> points = new ArrayList<>();
    points.add(new LatLng(end.getLatitude(), end.getLongitude()));
    points.add(new LatLng(last.getLatitude(), last.getLongitude()));

    Polyline ooPolyline = mAmap.addPolyline(new PolylineOptions().addAll(points).width(6).color(Color.BLUE));

    if (null == mLineList) {
        mLineList = new ArrayList<>();
    }
    mLineList.add(ooPolyline);

    ((MainActivity) getActivity()).setRangingDistance(mTotal);
}
 
Example 9
Source File: MoveTrackModel.java    From RunMap with Apache License 2.0 5 votes vote down vote up
@Override
public long onNewLocation(TrackPoint trackPoint) {
    LatLng cur = new LatLng(trackPoint.getLatitude(), trackPoint.getLongitude());
    if(mCoordinateLists.isEmpty()){
        mCoordinateLists.add(trackPoint);
        return 0;
    }
    LatLng pre = mCoordinateLists.get(mCoordinateLists.size() - 1).getLocation();
    mCoordinateLists.add(trackPoint);
    mDurationDistance += AMapUtils.calculateLineDistance(pre, cur);
    return mDurationDistance;
}
 
Example 10
Source File: BuildPresenterImpl.java    From RunMap with Apache License 2.0 5 votes vote down vote up
private boolean isClosed(TrackPoint cur,TrackPoint cmp){
    float distance = AMapUtils.calculateLineDistance(cur.getLocation(),cmp.getLocation());
    if(distance < RMConfiguration.MAX_DISTANCE){
        CFLog.e("Build","closed = "+distance);
        return true;
    }
    return false;
}
 
Example 11
Source File: SmoothMarker.java    From SmoothMove with MIT License 5 votes vote down vote up
/**
 * 设置平滑移动的经纬度数组
 *
 * @param points
 */
public void setPoints(List<LatLng> points) {
    this.points.clear();
    for (LatLng latLng : points) {
        this.points.add(latLng);
    }

    if (points.size() > 1) {
        endPoint = points.get(points.size() - 1);
        lastEndPoint = points.get(points.size() - 2);
    }

    eachDistance.clear();
    totalDistance = 0;

    //计算比例
    for (int i = 0; i < points.size() - 1; i++) {
        double distance = AMapUtils.calculateLineDistance(points.get(i), points.get(i + 1));
        eachDistance.add(distance);
        totalDistance += distance;
    }

    remainDistance = totalDistance;

    LatLng markerPoint = this.points.removeFirst();

    if (marker != null) {
        marker.setPosition(markerPoint);
        //判断是否使用正确的图标
        checkMarkerIcon();
    } else {
        if (descriptor == null) {
            useDefaultDescriptor = true;
        }
        marker = mAMap.addMarker(new MarkerOptions().belowMaskLayer(true).position
                (markerPoint).icon(descriptor).title("").anchor(0.5f, 0.5f));
    }

}
 
Example 12
Source File: ClusterOverlay.java    From android-cluster-marker with Apache License 2.0 5 votes vote down vote up
/**
 * 根据一个点获取是否可以依附的聚合点,没有则返回null
 *
 * @param latLng
 * @return
 */
private Cluster getCluster(LatLng latLng,List<Cluster>clusters) {
    for (Cluster cluster : clusters) {
        LatLng clusterCenterPoint = cluster.getCenterLatLng();
        double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint);
        if (distance < mClusterDistance && mAMap.getCameraPosition().zoom < 19) {
            return cluster;
        }
    }

    return null;
}
 
Example 13
Source File: AmapFragment.java    From BmapLite with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
    if (mIsModeRanging) {
        MyPoiModel poi = new MyPoiModel(TypeMap.TYPE_AMAP);
        poi.setLatitude(marker.getPosition().latitude);
        poi.setLongitude(marker.getPosition().longitude);

        mPoiList.add(poi);

        makeRangingMarker(poi);
        setRangingPolyLine();
    } else {
        int distance = 0;
        if (null != BApp.MY_LOCATION) {
            distance = (int) AMapUtils.calculateLineDistance(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude()), marker.getPosition());
        }

        if (null == clickMapPoiNow) {
            clickMapPoiNow = new MyPoiModel(TypeMap.TYPE_AMAP);
        }
        if (null != marker.getTitle() && !marker.getTitle().isEmpty()) {
            clickMapPoiNow.setTypeMap(TypeMap.TYPE_AMAP);
            clickMapPoiNow.setName(marker.getTitle());
            clickMapPoiNow.setLongitude(marker.getPosition().longitude);
            clickMapPoiNow.setLatitude(marker.getPosition().latitude);
            mAmap.animateCamera(CameraUpdateFactory.changeLatLng(new LatLng(clickMapPoiNow.getLatitude(), clickMapPoiNow.getLongitude())));
            ((MainActivity) getActivity()).showPoiLay(clickMapPoiNow, distance);
        } else {
            ((MainActivity) getActivity()).showPoiLay(BApp.MY_LOCATION, distance);
        }

    }
    return true;
}
 
Example 14
Source File: CalculateDistanceActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 *  在marker拖动过程中回调此方法, 这个marker的位置可以通过getPosition()方法返回。
 *  这个位置可能与拖动的之前的marker位置不一样。
 *  marker 被拖动的marker对象。
    */
@Override
public void onMarkerDrag(Marker marker) {

	distance = AMapUtils.calculateLineDistance(makerA.getPosition(), makerB.getPosition());
	Text.setText("长按Marker可拖动\n两点间距离为:"+distance+"m");
	
}
 
Example 15
Source File: CalculateDistanceActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	
	super.onCreate(savedInstanceState);
	setContentView(R.layout.arc_activity);
	mapView = (MapView) findViewById(R.id.map);
	mapView.onCreate(savedInstanceState);// 此方法必须重写
	init();
	distance = AMapUtils.calculateLineDistance(makerA.getPosition(), makerB.getPosition());
	Text.setText("长按Marker可拖动\n两点间距离为:"+distance+"m");
}
 
Example 16
Source File: ParticleWeatherMapActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 获取是哪里需要显示天气
 *
 * @param position
 * @return
 */
private String getShowWeatherPositio(CameraPosition position) {
    if(position == null) {
        return null;
    }

    List<Marker> markers = aMap.getMapScreenMarkers();

    // 去除离屏幕最近的marker
    Marker needShowMarker = null;
    float distance = 0;
    for (Marker marker : markers) {
        LatLng markerPos = marker.getPosition();

        float curDistanct = AMapUtils.calculateLineDistance(markerPos, position.target);

        if(distance == 0) {
            distance = curDistanct;
            needShowMarker = marker;
        } else {
            if(curDistanct < distance) {
                needShowMarker = marker;
            }
        }

    }


    if(needShowMarker != null && needShowMarker.getObject() != null) {
        return (String) needShowMarker.getObject();
    }
    return null;
}
 
Example 17
Source File: GaoDeMapAiSurroundManager.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public float getSurroundRadius(double lastLogitude, double lastLatitude, double currentLogitude, double currentLatitude) {
    FLatLng last = GpsCorrect.Earth_To_Mars(lastLatitude, lastLogitude);
    FLatLng currrent = GpsCorrect.Earth_To_Mars(currentLatitude, currentLogitude);
    return AMapUtils.calculateLineDistance(new LatLng(last.latitude, last.longitude), new LatLng(currrent.latitude, currrent.longitude));
}
 
Example 18
Source File: CommonUtils.java    From NewFastFrame with Apache License 2.0 4 votes vote down vote up
public static String getDistance(double longitude, double latitude) {
        double localLongitude = UserManager.getInstance().getCurrentUser().getLocation().getLongitude();
        double localLatitude = UserManager.getInstance().getCurrentUser().getLocation().getLatitude();
        int distance = (int) AMapUtils.calculateLineDistance(new LatLng(localLatitude, localLongitude), new LatLng(latitude, longitude));
        return distance + "";
}
 
Example 19
Source File: CommonUtils.java    From TestChat with Apache License 2.0 4 votes vote down vote up
public static String getDistance(double longitude, double latitude) {
        double localLongitude = UserManager.getInstance().getCurrentUser().getLocation().getLongitude();
        double localLatitude = UserManager.getInstance().getCurrentUser().getLocation().getLatitude();
        int distance = (int) AMapUtils.calculateLineDistance(new LatLng(localLatitude, localLongitude), new LatLng(latitude, longitude));
        return distance + "";
}
 
Example 20
Source File: MapDrawer.java    From RunMap with Apache License 2.0 4 votes vote down vote up
public void drawTrackAnimation(List<LatLng> drawSource, int currentIndex, SmoothMoveMarker.MoveListener moveListener) {
    //寻找与起点距离最远的点
    SmoothMoveMarker pre = mMarkerLists.peek();
    if(pre != null){
        pre.setMoveListener(null);
        mMarkerLists.poll();
    }
    float maxDistance = 0;
    LatLng endPoint = null;
    for (int i = 1; i < drawSource.size(); i++) {
        float distance = AMapUtils.calculateLineDistance(drawSource.get(0), drawSource.get(i));
        if (distance > maxDistance) {
            endPoint = drawSource.get(i);
            maxDistance = distance;
        }
    }
    CFLog.e("TAG", "max distance = " + maxDistance);

    //代表构成的一个矩形区域,由两点决定
    LatLngBounds bounds = new LatLngBounds(drawSource.get(0), endPoint);

    float pad = GlobalApplication.getAppContext().getResources().getDisplayMetrics().scaledDensity * RMConfiguration.MAP_PADDING;
    mAmap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(drawSource.get(0), 17, 0, 0)));
    mAmap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, (int) pad));

    drawSingleMaker(drawSource.get(0), GlobalApplication.getAppContext().getString(R.string.string_start_point), -1);
    drawSingleMaker(drawSource.get(drawSource.size() - 1), GlobalApplication.getAppContext().getString(R.string.string_end_point), -1);
    if (currentIndex == 0) {
        drawPolyLineWithTexture(drawSource, R.mipmap.track_line_texture);
    } else {
        Random random = new Random(SystemClock.currentThreadTimeMillis());

        drawPolyLine(drawSource, Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
    }


    //按照指定的经纬度数据和时间,平滑移动
    SmoothMoveMarker smoothMarker = new SmoothMoveMarker(mAmap);
    // 设置滑动的图标
    smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.mipmap.track_line_icon));
    // 设置滑动的轨迹点
    smoothMarker.setPoints(drawSource);
    // 设置滑动的总时间
    smoothMarker.setTotalDuration(20);
    //设置监听
    smoothMarker.setMoveListener(moveListener);
    // 开始滑动
    smoothMarker.startSmoothMove();
    mMarkerLists.add(smoothMarker);
}