//弹出Dialog 选择外部地图
private void setMap(){
final Dialog dia=new AlertDialog.Builder(mContext).create();
View view=LayoutInflater.from(mContext).inflate(R.layout.dialog_map, null);
dia.show();
dia.getWindow().setContentView(view);
TextView tv_baidu=(TextView) view.findViewById(R.id.tv_baidu);
TextView tv_quxiao=(TextView) view.findViewById(R.id.tv_quxiao);
TextView tv_gaode=(TextView) view.findViewById(R.id.tv_gaode);
//调用外部百度地图
tv_baidu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
baidu();
dia.dismiss();
}
});
//调用外部高德地图
tv_gaode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
gaoDe();
dia.dismiss();
}
});
//取消对话框
tv_quxiao.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dia.dismiss();
}
});
}
//调用外部高德地图方法
private void gaoDe(){
if (Contacts.isAvilible(mContext, "com.autonavi.minimap")) {
try{
Intent intent = Intent.getIntent("androidamap://navi?sourceApplication=慧医&poiname=我的目的地&lat="+终点纬度+"&lon="+终点经度+"&dev=0");
mContext.startActivity(intent);
} catch (URISyntaxException e)
{e.printStackTrace(); }
}else{
Toast.makeText(mContext, "您尚未安装高德地图", Toast.LENGTH_LONG).show();
Uri uri = Uri.parse("market://details?id=com.autonavi.minimap");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
mContext.startActivity(intent);
}
}
private void baidu(){
//起点经纬度
LatLng sLatLng=new LatLng(Double.parseDouble(MyApp.getWeidu()),Double.parseDouble(MyApp.getJingdu()));
//终点经纬度
LatLng eLatLng=new LatLng(Double.parseDouble(lat), Double.parseDouble(lng));
RouteParaOption para = new RouteParaOption();
para.startName("从这里开始");
para.startPoint(sLatLng);
para.endName(address);//起点位置
para.endPoint(eLatLng);
try {
BaiduMapRoutePlan.openBaiduMapDrivingRoute(para, this);
//BaiduMapNavigation.openBaiduMapNavi(para, this);
} catch (BaiduMapAppNotSupportNaviException e) {
e.printStackTrace();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("您尚未安装百度地图app或app版本过低,点击确认安装?");
builder.setTitle("提示");
builder.setPositiveButton("确认", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
OpenClientUtil.getLatestBaiduMapApp(mContext);
//BaiduMapNavigation.
}
});
builder.setNegativeButton("取消", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
}
//dialog 布局dialog_map
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/white"
android:orientation="vertical" >
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="center"
android:layout_gravity="center"
android:text="百度地图"
android:textColor="#006CD8"
android:textSize="16sp" />
android:layout_height="0.5dp"
android:background="@color/line"
android:paddingLeft="5dp"
android:layout_gravity="center_horizontal"
android:paddingRight="5dp"
/>
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="center"
android:layout_gravity="center"
android:text="高德地图"
android:textColor="#006CD8"
android:textSize="16sp" />
android:layout_height="0.5dp"
android:background="@color/line" />
android:layout_height="50dp"
android:orientation="horizontal" >
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="取消"
android:layout_gravity="center"
android:textColor="#006CD8"
android:textSize="18sp" />