com.baidu.mapapi.utils.DistanceUtil Java Examples

The following examples show how to use com.baidu.mapapi.utils.DistanceUtil. 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: PoiSearchAdapter.java    From MoveMapLocation with 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 #2
Source File: NaviConfirmPointActivity.java    From AssistantBySDK with 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 File: TrafficShowPresenter.java    From AssistantBySDK with 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 File: NavUtil.java    From Mobike with 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 File: NavUtil.java    From Mobike with 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 File: FreightTrackBaiduMapFragment.java    From ESeal with 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 File: FreightTrackBaiduMapFragment.java    From ESeal with 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 File: FreightTrackMapWithWebViewFragment.java    From ESeal with 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 File: FreightTrackMapWithWebViewFragment.java    From ESeal with 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 File: FreightTrackMapFragment.java    From ESeal with 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 File: SearchAddressAdapter.java    From FastWaiMai with 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 #12
Source File: FreightTrackGoogleMapFragment.java    From ESeal with 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 #13
Source File: FreightTrackGoogleMapFragment.java    From ESeal with 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 #14
Source File: NaviSetPointPresenter.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public void toCompanyNavi() {
    BDLocation bl = new BDLocation();
    bl.setLatitude(address.getLatitude());
    bl.setLongitude(address.getLongitude());
    // bl = LocationClient.getBDLocationInCoorType(bl, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);
    double dt = DistanceUtil.getDistance(new LatLng(bl.getLatitude(), bl.getLongitude()), new LatLng(companyAddress.getLatitude(), companyAddress.getLongitude()));
    if (dt < 50) {
        mSetPointView.showSnackBar(mAppConfig.getResources().getString(R.string.inCompany));
        //  Toast.makeText(mContext, mAppConfig.getResources().getString(R.string.inCompany), Toast.LENGTH_SHORT).show();

    } else {
        //没有网络进行提示
        if (NetUtil.getInstance(mContext).getCurrentNetType().equals(NetUtil.NetType.NETWORK_TYPE_NONE)) {
            final CommonDialog commonDialog = new CommonDialog(mContext, "网络错误", "网络状态不佳,请检查网络设置", "确定");
            commonDialog.setOnConfirmListener(new CommonDialog.OnConfirmListener() {
                @Override
                public void onConfirm() {
                    commonDialog.cancel();
                }
            }).show();
            return;
        }
        Intent intent = new Intent(mContext, NaviSetLineActivity.class);
        intent.putExtra("latitude", companyAddress.getLatitude());
        intent.putExtra("longitude", companyAddress.getLongitude());
        intent.putExtra("address", companyAddress.getName());
        mContext.startActivity(intent);
        mContext.goInto();
    }

}
 
Example #15
Source File: NaviSetPointPresenter.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public void toHomeNavi() {
    BDLocation bl = new BDLocation();
    bl.setLatitude(address.getLatitude());
    bl.setLongitude(address.getLongitude());
    // bl = LocationClient.getBDLocationInCoorType(bl, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);
    double dt = DistanceUtil.getDistance(new LatLng(bl.getLatitude(), bl.getLongitude()), new LatLng(homeAddress.getLatitude(), homeAddress.getLongitude()));
    if (dt < 50) {
        mSetPointView.showSnackBar(mAppConfig.getResources().getString(R.string.inHome));
        // Toast.makeText(mContext, mAppConfig.getResources().getString(R.string.inHome), Toast.LENGTH_SHORT).show();
    }//else if(dt>100000){
    //            Toast.makeText(mContext, mAppConfig.getResources().getString(R.string.tooLongForCalculate), Toast.LENGTH_SHORT).show();
    //        }
    else {
        //没有网络进行提示
        if (NetUtil.getInstance(mContext).getCurrentNetType().equals(NetUtil.NetType.NETWORK_TYPE_NONE)) {
            final CommonDialog commonDialog = new CommonDialog(mContext, "网络错误", "网络状态不佳,请检查网络设置", "确定");
            commonDialog.setOnConfirmListener(new CommonDialog.OnConfirmListener() {
                @Override
                public void onConfirm() {
                    commonDialog.cancel();
                }
            }).show();
            return;
        }
        Intent intent = new Intent(mContext, NaviSetLineActivity.class);
        intent.putExtra("latitude", homeAddress.getLatitude());
        intent.putExtra("longitude", homeAddress.getLongitude());
        intent.putExtra("address", homeAddress.getName());
        mContext.startActivity(intent);
        mContext.goInto();
    }
}
 
Example #16
Source File: GetDistanceModule.java    From react-native-baidu-map with MIT License 5 votes vote down vote up
@ReactMethod
public void getLocationDistance(double lat1, double lng1, double lat2, double lng2, Promise promise) {
    WritableMap params = Arguments.createMap();
    LatLng p1 = new LatLng(lat1, lng1);
    LatLng p2 = new LatLng(lat2, lng2);
    //计算p1、p2两点之间的直线距离,单位:米
    double distance = DistanceUtil.getDistance(p1, p2);
    params.putDouble("distance", distance);
    promise.resolve(params);
}
 
Example #17
Source File: TrafficShowPresenter.java    From AssistantBySDK with 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);
}
 
Example #18
Source File: BaiduMapFragment.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_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 #19
Source File: NaviConfirmPointActivity.java    From AssistantBySDK with 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 #20
Source File: BaiduMapFragment.java    From BmapLite with 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 #21
Source File: BaiduMapFragment.java    From BmapLite with 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 #22
Source File: BaiduMapFragment.java    From BmapLite with 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 #23
Source File: RouteActivity.java    From BmapLite with 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 #24
Source File: AddressEditDelegate.java    From FastWaiMai with 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 #25
Source File: MainActivity.java    From BaiDuMapSelectDemo with 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 #26
Source File: Adapter_SearchAddress.java    From BaiDuMapSelectDemo with 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 #27
Source File: BaiduMapFragment.java    From BmapLite with 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 #28
Source File: BaiduMapFragment.java    From BmapLite with 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 #29
Source File: BaiduMapFragment.java    From BmapLite with 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 #30
Source File: BaiduMapFragment.java    From BmapLite with 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);
    }
}