融云添加百度地图导航

在回话界面的ACTIVITY实现RongIM.ConversationBehaviorListener,重写onMessageClick 方法,代码如下:

@Override
public boolean onMessageClick(Context context, View view, Message arg2) {
    if (arg2.getContent() instanceof LocationMessage) {
        Intent intent = new Intent(ConversationActivity.this, GuideActivity.class);
        intent.putExtra("location", arg2.getContent());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return true;
    } else {
        return false;
    }
}
注:GuideActivity为自定义的点击位置消息后弹出的界面,此类代码如下:

public class GuideActivity extends RongBaseActivity {
    private MapView mAMapView;
    private LinearLayout guide;
    private double lat;
    private double lng;
    private String poi;
    public GuideActivity() {
    }
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(io.rong.imkit.R.layout.rc_location_preview_activity);
        this.mAMapView = (MapView) this.findViewById(io.rong.imkit.R.id.rc_ext_amap);
        this.mAMapView.onCreate(savedInstanceState);
        TextView title = (TextView) this.findViewById(io.rong.imkit.R.id.rc_action_bar_title);
        title.setText(io.rong.imkit.R.string.rc_plugin_location);
        this.initMap();
        guide = (LinearLayout) findViewById(R.id.guide);//这是增加的按钮,点击调用百度地图,实现导航功能
        new Thread(new Runnable() {
            @Override
            public void run() {
                guide.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        try {
                            Intent intent = Intent.getIntent("intent://map/direction?origin=latlng:" + lat + "," + lng + "|name:我的位置&destination="+poi+"&mode=driving®ion=&referer=Autohome|GasStation#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
                            if (isInstallByread("com.baidu.BaiduMap")) {
                                startActivity(intent); //启动调用
                                Log.e("GasStation", "百度地图客户端已经安装");
                            } else {
                                Log.e("GasStation", "没有安装百度地图客户端");
                                Toast.makeText(GuideActivity.this, "请先安装百度地图", Toast.LENGTH_SHORT).show();
                            }
                        } catch (URISyntaxException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        }).start();
    }
    private void initMap() {
        AMap amap = this.mAMapView.getMap();
        amap.setMyLocationEnabled(true);
        amap.getUiSettings().setZoomControlsEnabled(false);
        amap.getUiSettings().setMyLocationButtonEnabled(false);
        Intent intent = this.getIntent();
        LocationMessage locationMessage = (LocationMessage) intent.getParcelableExtra("location");
        lat = locationMessage.getLat();
        lng = locationMessage.getLng();
        poi = locationMessage.getPoi();
        amap.addMarker((new MarkerOptions()).anchor(0.5F, 0.5F).position(new LatLng(lat, lng)).title(poi).snippet(lat + "," + lng).draggable(false));
        amap.moveCamera(CameraUpdateFactory.newCameraPosition((new CameraPosition.Builder()).target(new LatLng(lat, lng)).zoom(16.0F).bearing(0.0F).tilt(30.0F).build()));
    }
    private boolean isInstallByread(String packageName) {
        return new File("/data/data/" + packageName).exists();
    }
    protected void onDestroy() {
        this.mAMapView.onDestroy();
        super.onDestroy();
    } 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值