Java Code Examples for com.baidu.mapapi.utils.DistanceUtil

The following examples show how to use com.baidu.mapapi.utils.DistanceUtil. These examples are extracted from open source projects. 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 Project: FastWaiMai   Source File: SearchAddressAdapter.java    License: MIT License 6 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, PoiInfo item) {

    final ImageView ivPointImage = helper.getView(R.id.iv_point);
    final TextView tvName = helper.getView(R.id.tv_name);
    final TextView tvAddress = helper.getView(R.id.tv_address);
    final TextView tvDistance = helper.getView(R.id.tv_distance);
    LatLng latLng = item.getLocation();

    double distance = DistanceUtil.getDistance(currentLatLng, latLng);
    if(helper.getPosition() == 0){
        ivPointImage.setImageResource(R.drawable.point_orange);
        tvName.setTextColor(Latte.getApplication().getResources().getColor(R.color.orange));
    }else{
        ivPointImage.setImageResource(R.drawable.point_gray);
        tvName.setTextColor(Latte.getApplication().getResources().getColor(R.color.black));
    }
    tvName.setText(item.getName());
    tvAddress.setText(item.getAddress());
    tvDistance.setText(formatDistance(distance));
}
 
Example 2
Source Project: AssistantBySDK   Source File: NaviConfirmPointActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(NaviPointHolder holder, int position) {
    PoiInfo poiInfo = list.get(position);
    holder.mTpiNameText.setText((position + 1) + "." + poiInfo.name);
    holder.mTpiAddressText.setText(poiInfo.address);
    if (addMode) {
        holder.mTpiItemConfirmText.setText("添加");
        holder.mTpiDistanceText.setVisibility(View.GONE);
    } else {
        holder.mTpiItemConfirmText.setText("出发");
        holder.mTpiDistanceText.setVisibility(View.VISIBLE);
        double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
                poiInfo.location) / 1000;
        holder.mTpiDistanceText.setText(String.format("%.1f", distance) + "km");
    }
    holder.mTpiTargetConfirmBt.setTag(position);
    holder.itemView.setTag(position);
}
 
Example 3
Source Project: AssistantBySDK   Source File: TrafficShowPresenter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void update(Address addr) {
    Log.i(TAG, "onReceiveLocation>>");
    if (addr == null)
        return;
    // BDLocation location = new BDLocation();
    // location.setLatitude(addr.getLatitude());
    // location.setLongitude(addr.getLongitude());
    // location = LocationClient.getBDLocationInCoorType(location, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);
    LatLng now = new LatLng(addr.getLatitude(), addr.getLongitude());
    // location.setLatitude(address.getLatitude());
    // location.setLongitude(address.getLongitude());
    // location = LocationClient.getBDLocationInCoorType(location, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);
    LatLng before = new LatLng(address.getLatitude(), address.getLongitude());

    address = addr;
    // ((TextView) mContext.findViewById(R.id.ast_location_text)).setText(addr.getAddressDetail());
    if (DistanceUtil.getDistance(before, now) > 2000) {
        updateHomeAndCompany();
        if (goHomeNodes.size() > 0)
            setGoHomeCalculate();
        else
            setGoCompanyCalculate();
    }
}
 
Example 4
Source Project: Mobike   Source File: NavUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 启动百度地图骑行导航(Native)
 */
private static void startBikingNavi(Activity activity, LatLng startLL, LatLng endLL) {
    //距离太近toast提示(100米内)
    double dis = DistanceUtil.getDistance(new LatLng(startLL.latitude, startLL.longitude), new LatLng(endLL.latitude, endLL.longitude));
    if (dis <= 100) {
        Toast.makeText(activity, "起点、途经点、终点距离太近", Toast.LENGTH_SHORT).show();
        return;
    }
    // 构建 导航参数
    NaviParaOption para = new NaviParaOption()
            .startPoint(startLL).endPoint(endLL);
    try {
        BaiduMapNavigation.openBaiduMapBikeNavi(para, activity);
    } catch (BaiduMapAppNotSupportNaviException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source Project: Mobike   Source File: NavUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 通过Uri跳转到百度地图导航
 */
public static void startNative_Baidu(Activity activity, LatLng pt1, LatLng pt2, String start_address, String end_address) {
    try {
        double dis = DistanceUtil.getDistance(new LatLng(pt1.latitude,pt1.longitude), new LatLng(pt2.latitude,pt2.longitude));
        if (dis <= 100) {
            Toast.makeText(activity, "起点、途经点、终点距离太近", Toast.LENGTH_SHORT).show();
            return;
        }
        String start_latlng = pt1.latitude + "," + pt1.longitude;
        String end_latlng = pt2.latitude + "," + pt2.longitude;
        Intent intent = Intent.getIntent("intent://map/direction?origin=latlng:"+start_latlng+"|name:"+"Start"+"&destination=latlng:"+end_latlng+"|name:"+"End"+"&mode=riding&src=这里随便写#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
        Log.d("gaolei", "---------------" + start_address + "," + end_address);
        activity.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(activity, "地址解析错误", Toast.LENGTH_SHORT).show();
    }
}
 
Example 6
Source Project: ESeal   Source File: FreightTrackBaiduMapFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取百度地图显示等级
 * 范围3-21级
 */
private int getZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance <= 100.0d) {
        return 16;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 19 - i + 3;
        }
    }
    return 16;
}
 
Example 7
Source Project: ESeal   Source File: FreightTrackBaiduMapFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取Google地图显示等级
 * 范围0-18级
 */
private int getGoogleMapZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance == 0.0d) {
        return 12;
    }
    if (distance > 0.0d && distance <= 100.0d) {
        return 18;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 18 - i;
        }
    }
    return 12;
}
 
Example 8
Source Project: ESeal   Source File: FreightTrackMapWithWebViewFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取百度地图显示等级
 * 范围3-21级
 */
private int getZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance <= 100.0d) {
        return 16;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 19 - i + 3;
        }
    }
    return 16;
}
 
Example 9
Source Project: ESeal   Source File: FreightTrackMapWithWebViewFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取Google地图显示等级
 * 范围0-18级
 */
private int getGoogleMapZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance == 0.0d) {
        return 12;
    }
    if (distance > 0.0d && distance <= 100.0d) {
        return 18;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 18 - i;
        }
    }
    return 12;
}
 
Example 10
Source Project: ESeal   Source File: FreightTrackMapFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取百度地图显示等级
 * 范围3-21级
 */
private int getZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance <= 100.0d) {
        return 16;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 19 - i + 3;
        }
    }
    return 16;
}
 
Example 11
Source Project: ESeal   Source File: FreightTrackGoogleMapFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取百度地图显示等级
 * 范围3-21级
 */
private int getZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance <= 100.0d) {
        return 16;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 19 - i + 3;
        }
    }
    return 16;
}
 
Example 12
Source Project: ESeal   Source File: FreightTrackGoogleMapFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取Google地图显示等级
 * 范围0-18级
 */
private int getGoogleMapZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance == 0.0d) {
        return 12;
    }
    if (distance > 0.0d && distance <= 100.0d) {
        return 18;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 18 - i;
        }
    }
    return 12;
}
 
Example 13
Source Project: MoveMapLocation   Source File: PoiSearchAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = LayoutInflater.from(context).inflate(R.layout.poisearch_item, null);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    PoiInfo poiInfo = poiInfos.get(position);
    holder.poisearch_name.setText(poiInfo.name);
    holder.poisearch_address.setText(poiInfo.address);
    holder.poisearch_distance.setText((int)DistanceUtil.getDistance(locationLatLng, poiInfo.location)+"米");
    return convertView;
}
 
Example 14
Source Project: BmapLite   Source File: BaiduMapFragment.java    License: 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_BAIDU);
        poi.setLatitude(marker.getPosition().latitude);
        poi.setLongitude(marker.getPosition().longitude);

        if (null == mPoiList) {
            mPoiList = new ArrayList<>();
        }
        mPoiList.add(poi);

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

        if (null == clickMapPoiNow) {
            clickMapPoiNow = new MyPoiModel(TypeMap.TYPE_BAIDU);
        }
        clickMapPoiNow.setTypeMap(TypeMap.TYPE_BAIDU);
        clickMapPoiNow.setName(marker.getTitle());
        clickMapPoiNow.setLongitude(marker.getPosition().longitude);
        clickMapPoiNow.setLatitude(marker.getPosition().latitude);
        ((MainActivity) getActivity()).showPoiLay(clickMapPoiNow, distance);

        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newLatLng(new LatLng(clickMapPoiNow.getLatitude(), clickMapPoiNow.getLongitude())));
    }


    return true;
}
 
Example 15
Source Project: BmapLite   Source File: BaiduMapFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void makeMarker(MyPoiModel poi, boolean isClear) {
//        if (isClear) {
//            clearMarker();
//        }
//
//        //构建Marker图标
//        BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
//        //构建MarkerOption,用于在地图上添加Marker
//        OverlayOptions option = new MarkerOptions().title(poi.getName()).position(poi.getLatLngBaidu(getActivity())).icon(bitmap).animateType(MarkerOptions.MarkerAnimateType.none);
//        //在地图上添加Marker,并显示
//        mBaiduMap.addOverlay(option);
//
//        MapStatus.Builder builder = new MapStatus.Builder();
//        builder.target(poi.getLatLngBaidu(getActivity()));
//        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));

        makeMarker(poi, isClear, 0);

        int distance = 0;
        if (null != BApp.MY_LOCATION) {
            distance = (int) DistanceUtil.getDistance(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude()),
                    new LatLng(poi.getLatitude(), poi.getLongitude()));
        }

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

    }
 
Example 16
Source Project: BmapLite   Source File: BaiduMapFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void setRangingPolyLine() {
    if (null == mPoiList || 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 += DistanceUtil.getDistance(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()));

    OverlayOptions ooPolyline = new PolylineOptions().width(6).color(Color.BLUE).points(points);
    Overlay line = mBaiduMap.addOverlay(ooPolyline);

    if (mOverlayList == null) {
        mOverlayList = new ArrayList<>();
    }
    mOverlayList.add(line);

    ((MainActivity) getActivity()).setRangingDistance(mTotal);
}
 
Example 17
Source Project: BmapLite   Source File: BaiduMapFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void deleteRangingPoi() {
    if (null == mPoiList || mOverlayList == null) {
        return;
    }
    if (mPoiList.size() > 1) {
        MyPoiModel end = mPoiList.get(mPoiList.size() - 1);
        MyPoiModel pre = mPoiList.get(mPoiList.size() - 2);

        mTotal -= DistanceUtil.getDistance(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 (!mOverlayList.isEmpty()) {
        mOverlayList.get(mOverlayList.size() - 1).remove();
        mOverlayList.remove(mOverlayList.size() - 1);
    }

    if (!mOverlayList.isEmpty()) {
        mOverlayList.get(mOverlayList.size() - 1).remove();
        mOverlayList.remove(mOverlayList.size() - 1);
    }
}
 
Example 18
Source Project: BmapLite   Source File: RouteActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
public int getDistance() {
    if (null == mPoiStart || null == mPoiEnd) {
        return 0;
    }
    return (int) DistanceUtil.getDistance(new LatLng(mPoiStart.getLatitude(), mPoiStart.getLongitude()),
            new LatLng(mPoiEnd.getLatitude(), mPoiEnd.getLongitude()));
}
 
Example 19
Source Project: FastWaiMai   Source File: AddressEditDelegate.java    License: MIT License 5 votes vote down vote up
private void initSuggestionSearch() {
	// 初始化建议搜索模块,注册建议搜索事件监听(sug搜索)
	mSuggestionSearch = SuggestionSearch.newInstance();
	mSuggestionSearch.setOnGetSuggestionResultListener(new OnGetSuggestionResultListener() {
		/**
		 * 获取在线建议搜索结果,得到requestSuggestion返回的搜索结果
		 * @param suggestionResult    Sug检索结果
		 */
		@Override
		public void onGetSuggestionResult(SuggestionResult suggestionResult) {
			if (suggestionResult == null || suggestionResult.getAllSuggestions() == null) {
				Toast.makeText(getContext(), "未找到结果", Toast.LENGTH_LONG).show();
				return;
			}

			List<SuggestionResult.SuggestionInfo> sugList = suggestionResult.getAllSuggestions();
			for (SuggestionResult.SuggestionInfo info : sugList) {
				if (info.key != null) {
					Log.e(TAG, "搜索结果:" + info.toString());
					Log.e(TAG, "key:" + info.key);
					DecimalFormat df = new DecimalFormat("######0");
					//用当前所在位置算出距离
					String distance = df.format(DistanceUtil.getDistance(currentLatLng, info.pt));
					Log.e(TAG, "距离:" + distance);
				}
			}

		}
	});
}
 
Example 20
Source Project: BaiDuMapSelectDemo   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void initSuggestionSearch() {
    // 初始化建议搜索模块,注册建议搜索事件监听(sug搜索)
    mSuggestionSearch = SuggestionSearch.newInstance();
    mSuggestionSearch.setOnGetSuggestionResultListener(new OnGetSuggestionResultListener() {
        /**
         * 获取在线建议搜索结果,得到requestSuggestion返回的搜索结果
         * @param suggestionResult    Sug检索结果
         */
        @Override
        public void onGetSuggestionResult(SuggestionResult suggestionResult) {
            if (suggestionResult == null || suggestionResult.getAllSuggestions() == null) {
                Toast.makeText(mContext, "未找到结果", Toast.LENGTH_LONG).show();
                return;
            }

            List<SuggestionResult.SuggestionInfo> sugList = suggestionResult.getAllSuggestions();
            for (SuggestionResult.SuggestionInfo info : sugList) {
                if (info.key != null) {
                    Log.e(TAG, "搜索结果:" + info.toString());
                    Log.e(TAG, "key:" + info.key);
                    DecimalFormat df = new DecimalFormat("######0");
                    //用当前所在位置算出距离
                    String distance = df.format(DistanceUtil.getDistance(currentLatLng, info.pt));
                    Log.e(TAG, "距离:" + distance);
                }
            }

        }
    });
}
 
Example 21
Source Project: BaiDuMapSelectDemo   Source File: Adapter_SearchAddress.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
        convertView = oInflater.inflate(R.layout.item_search_address, null);
        viewHolder = new ViewHolder();
        //得到各个控件的对象
        viewHolder.iv_point = convertView.findViewById(R.id.iv_point);
        viewHolder.tv_name = convertView.findViewById(R.id.tv_name);
        viewHolder.tv_address = convertView.findViewById(R.id.tv_address);
        viewHolder.tv_distance = convertView.findViewById(R.id.tv_distance);
        //绑定viewHolder对象
        convertView.setTag(viewHolder);

    } else {
        //取出viewHolder对象
        viewHolder = (ViewHolder) convertView.getTag();
    }
    PoiInfo poiInfo = oList.get(position);
    LatLng latLng = poiInfo.getLocation();
    //用当前所在位置算出距离
    double distance=DistanceUtil.getDistance(currentLatLng, latLng);

    viewHolder.tv_name.setText(poiInfo.name);
    viewHolder.tv_address.setText(poiInfo.address);
    viewHolder.tv_distance.setText(formatDistance(distance));
    if (position == 0) {
        viewHolder.iv_point.setImageResource(R.drawable.point_orange);
        viewHolder.tv_name.setTextColor(ocontext.getResources().getColor(R.color.orange));
    }else{
        viewHolder.iv_point.setImageResource(R.drawable.point_gray);
        viewHolder.tv_name.setTextColor(ocontext.getResources().getColor(R.color.black));
    }
    return convertView;
}
 
Example 22
Source Project: BmapLite   Source File: BaiduMapFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
    if (mIsModeRanging) {
        MyPoiModel poi = new MyPoiModel(TypeMap.TYPE_BAIDU);
        poi.setLatitude(marker.getPosition().latitude);
        poi.setLongitude(marker.getPosition().longitude);

        if (null == mPoiList) {
            mPoiList = new ArrayList<>();
        }
        mPoiList.add(poi);

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

        if (null == clickMapPoiNow) {
            clickMapPoiNow = new MyPoiModel(TypeMap.TYPE_BAIDU);
        }
        clickMapPoiNow.setTypeMap(TypeMap.TYPE_BAIDU);
        clickMapPoiNow.setName(marker.getTitle());
        clickMapPoiNow.setLongitude(marker.getPosition().longitude);
        clickMapPoiNow.setLatitude(marker.getPosition().latitude);
        ((MainActivity) getActivity()).showPoiLay(clickMapPoiNow, distance);

        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newLatLng(new LatLng(clickMapPoiNow.getLatitude(), clickMapPoiNow.getLongitude())));
    }


    return true;
}
 
Example 23
Source Project: BmapLite   Source File: BaiduMapFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void makeMarker(MyPoiModel poi, boolean isClear) {
//        if (isClear) {
//            clearMarker();
//        }
//
//        //构建Marker图标
//        BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
//        //构建MarkerOption,用于在地图上添加Marker
//        OverlayOptions option = new MarkerOptions().title(poi.getName()).position(poi.getLatLngBaidu(getActivity())).icon(bitmap).animateType(MarkerOptions.MarkerAnimateType.none);
//        //在地图上添加Marker,并显示
//        mBaiduMap.addOverlay(option);
//
//        MapStatus.Builder builder = new MapStatus.Builder();
//        builder.target(poi.getLatLngBaidu(getActivity()));
//        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));

        makeMarker(poi, isClear, 0);

        int distance = 0;
        if (null != BApp.MY_LOCATION) {
            distance = (int) DistanceUtil.getDistance(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude()),
                    new LatLng(poi.getLatitude(), poi.getLongitude()));
        }

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

    }
 
Example 24
Source Project: BmapLite   Source File: BaiduMapFragment.java    License: Apache License 2.0 5 votes vote down vote up
public void setRangingPolyLine() {
    if (null == mPoiList || 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 += DistanceUtil.getDistance(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()));

    OverlayOptions ooPolyline = new PolylineOptions().width(6).color(Color.BLUE).points(points);
    Overlay line = mBaiduMap.addOverlay(ooPolyline);

    if (mOverlayList == null) {
        mOverlayList = new ArrayList<>();
    }
    mOverlayList.add(line);

    ((MainActivity) getActivity()).setRangingDistance(mTotal);
}
 
Example 25
Source Project: BmapLite   Source File: BaiduMapFragment.java    License: Apache License 2.0 5 votes vote down vote up
public void deleteRangingPoi() {
    if (null == mPoiList || mOverlayList == null) {
        return;
    }
    if (mPoiList.size() > 1) {
        MyPoiModel end = mPoiList.get(mPoiList.size() - 1);
        MyPoiModel pre = mPoiList.get(mPoiList.size() - 2);

        mTotal -= DistanceUtil.getDistance(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 (!mOverlayList.isEmpty()) {
        mOverlayList.get(mOverlayList.size() - 1).remove();
        mOverlayList.remove(mOverlayList.size() - 1);
    }

    if (!mOverlayList.isEmpty()) {
        mOverlayList.get(mOverlayList.size() - 1).remove();
        mOverlayList.remove(mOverlayList.size() - 1);
    }
}
 
Example 26
Source Project: BmapLite   Source File: RouteActivity.java    License: Apache License 2.0 5 votes vote down vote up
public int getDistance() {
    if (null == mPoiStart || null == mPoiEnd) {
        return 0;
    }
    return (int) DistanceUtil.getDistance(new LatLng(mPoiStart.getLatitude(), mPoiStart.getLongitude()),
            new LatLng(mPoiEnd.getLatitude(), mPoiEnd.getLongitude()));
}
 
Example 27
Source Project: AssistantBySDK   Source File: BaiduNaviSuperManager.java    License: Apache License 2.0 5 votes vote down vote up
public void zoomToRouteBound(BNRoutePlanNode start, BNRoutePlanNode end) {
    LatLng ws = new LatLng(start.getLatitude(), start.getLongitude());
    LatLng we = new LatLng(start.getLatitude(), end.getLongitude());
    int hd = (int) DistanceUtil.getDistance(ws, we);

    LatLng hs = new LatLng(start.getLatitude(), start.getLongitude());
    LatLng he = new LatLng(end.getLatitude(), start.getLongitude());
    int vd = (int) DistanceUtil.getDistance(hs, he);
    //Log.e(TAG,"hd="+hd+",vd="+vd);
    int level = getScales(hd, vd, Math.min(start.getLatitude(), end.getLatitude()));
    MapStatusProxy ms = BNMapControllerProxy.getInstance().getMapStatus();
    //Log.e(TAG,"level="+level);
    ms._Level = level;
    double cLatitude = Math.min(start.getLatitude(), end.getLatitude()) + Math.abs((start.getLatitude() - end.getLatitude()) / 2);
    double cLogitude = Math.min(start.getLongitude(), end.getLongitude()) + Math.abs((start.getLongitude() - end.getLongitude()) / 2);
    //Log.e(TAG,"lat="+cLatitude+",lng="+cLogitude);
    Bundle b1 = ZeroZeroProxy.bala2((int) (cLogitude * 1e5), (int) (cLatitude * 1e5));
    if (b1 != null) {
        ms._CenterPtX = b1.getInt("MCx");
        ms._CenterPtY = b1.getInt("MCy");
    }
    /*if (!BNavigatorProxy.getInstance().isNaviBegin()) {
        _Yoffest = 205;
        _Xoffest = 45;
    } else {
        _Yoffest = 60;
        _Xoffest = 30;
    }
    ms._Yoffset = ScreenUtil.getInstance().dip2px(_Yoffest);
    ms._Xoffset = 0 - ScreenUtil.getInstance().dip2px(_Xoffest);*/
    if (!BNavigatorProxy.getInstance().isNaviBegin())
        ms._Yoffset = ScreenUtil.getInstance().dip2px(100);

    BNMapControllerProxy.getInstance().setMapStatus(ms, BNMapControllerProxy.AnimationType.eAnimationLevel);
}
 
Example 28
Source Project: AssistantBySDK   Source File: NaviConfirmPointActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    View itemView = chilren.get(position);
    BaiduAddress address = aList.get(position);
    PagerHolder holder = null;
    /* 加载视图 */
    if (itemView == null) {
        itemView = mInflater.inflate(R.layout.target_poi_item_detail, null);
        chilren.put(position, itemView);
    }
    /* 绑定数据 */
    holder = new PagerHolder(itemView);
    holder.mTpidFavoriteBt.setTag(position);
    holder.mTpidSetTargetBt.setTag(position);
    holder.mTpidTargetConfirmBt.setTag(position);
    holder.mTpidNameText.setText((position + 1) + "." + address.getName());
    holder.mTpidAddressText.setText(address.getAddress());
    Double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
            new LatLng(address.getLatitude(), address.getLongitude())) / 1000;
    holder.mTpidDistanceText.setText(String.format("%.1f", distance) + "km");
    if (address.getFavoritedTime() != null) {
        holder.mTpidFavoriteBt.setText("已收藏");
        holder.mTpidFavoriteBt.getBackground().setLevel(1);
    }

    container.addView(itemView);
    return chilren.get(position);
}
 
Example 29
Source Project: AssistantBySDK   Source File: TrafficShowPresenter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(NaviPointHolder holder, int position) {
    PoiInfo poiInfo = poiInfoList.get(position);
    holder.mTpiNameText.setText((position + 1) + "." + poiInfo.name);
    holder.mTpiAddressText.setText(poiInfo.address);

    holder.mTpiItemConfirmText.setText("出发");
    holder.mTpiDistanceText.setVisibility(View.VISIBLE);
    double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
            poiInfo.location) / 1000;
    holder.mTpiDistanceText.setText(String.format("%.1f", distance) + "km");

    holder.mTpiTargetConfirmBt.setTag(position);
    holder.itemView.setTag(position);
}
 
Example 30
Source Project: AssistantBySDK   Source File: TrafficShowPresenter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    Log.i(TAG, "instantiateItem>>>" + position);
    View child = chilren.get(position);
    if (child == null) {
        child = inflater.inflate(R.layout.target_poi_item_detail, null);
        chilren.put(position, child);
    }
    child.findViewById(R.id.tpid_target_confirm_bt).setOnClickListener(clickListener);
    child.findViewById(R.id.tpid_target_confirm_bt).setTag(position);
    ((TextView) child.findViewById(R.id.tpid_name_text)).setText((position + 1) + "." + aList.get(position).getName());
    ((TextView) child.findViewById(R.id.tpid_address_text)).setText(aList.get(position).getAddress());
    Double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
            poiInfoList.get(position).location) / 1000;
    ((TextView) child.findViewById(R.id.tpid_distance_text)).setText(String.format("%.1f", distance) + "km");
    child.findViewById(R.id.tpid_set_target_bt).setOnClickListener(clickListener);
    child.findViewById(R.id.tpid_set_target_bt).setTag(position);
    TextView ft = (TextView) child.findViewById(R.id.tpid_favorite_bt);
    ft.setOnClickListener(clickListener);
    ft.setTag(position);
    if (aList.get(position).getFavoritedTime() != null) {
        ft.setText("已收藏");
        ((LevelListDrawable) ft.getBackground()).setLevel(1);
    }
    container.addView(child, 0);
    return chilren.get(position);
}