Android调用google地图生成路线图实现代码
作者:
Android程序调用本机google地图并且传递起始和终点位置生成路线图,有需要的朋有可以参考下,或许本文对你有所帮助,好了话不多说,看代码
Android程序调用本机googlemap,传递起始和终点位置,生成路线图
if (wodeweizhiPoint != null) {
if (wodeweizhiPoint.getLatitudeE6() != 0) {
float chufajingdu = (float) (wodeweizhiPoint.getLongitudeE6() / 1E6);
float chufaweidu = (float) (wodeweizhiPoint.getLatitudeE6() / 1E6);
float daodajingdu = (float) (AppConstant.PointZuoBiao.liangxiangDaoHangPoint.getLongitudeE6() / 1E6);
float daodaweidu = (float) (AppConstant.PointZuoBiao.liangxiangDaoHangPoint.getLatitudeE6() / 1E6);
// 标记一个点
// Intent i = new
// Intent(Intent.ACTION_VIEW,Uri.parse("http://ditu.google.cn/maps?hl=zh&mrt=loc&q=31.249351,121.45905"));
// 从哪到哪的路线
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("http://ditu.google.cn/maps?f=d&source=s_d&saddr="
+ chufaweidu
+ ","
+ chufajingdu
+ "&daddr="
+ daodaweidu
+ ","
+ daodajingdu + "&hl=zh"));
//如果强制使用googlemap地图客户端打开,就加下面两句
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK& Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
i.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(i);
}
} else {
AlertUtils.ToastAlert(mContext, “由于无法获取到您的位置,所以暂时无法提供导航”);
}
复制代码 代码如下:
if (wodeweizhiPoint != null) {
if (wodeweizhiPoint.getLatitudeE6() != 0) {
float chufajingdu = (float) (wodeweizhiPoint.getLongitudeE6() / 1E6);
float chufaweidu = (float) (wodeweizhiPoint.getLatitudeE6() / 1E6);
float daodajingdu = (float) (AppConstant.PointZuoBiao.liangxiangDaoHangPoint.getLongitudeE6() / 1E6);
float daodaweidu = (float) (AppConstant.PointZuoBiao.liangxiangDaoHangPoint.getLatitudeE6() / 1E6);
// 标记一个点
// Intent i = new
// Intent(Intent.ACTION_VIEW,Uri.parse("http://ditu.google.cn/maps?hl=zh&mrt=loc&q=31.249351,121.45905"));
// 从哪到哪的路线
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("http://ditu.google.cn/maps?f=d&source=s_d&saddr="
+ chufaweidu
+ ","
+ chufajingdu
+ "&daddr="
+ daodaweidu
+ ","
+ daodajingdu + "&hl=zh"));
//如果强制使用googlemap地图客户端打开,就加下面两句
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK& Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
i.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(i);
}
} else {
AlertUtils.ToastAlert(mContext, “由于无法获取到您的位置,所以暂时无法提供导航”);
}
您可能感兴趣的文章:
- Android中利用App实现消息推送机制的代码
- Android开发笔记之:消息循环与Looper的详解
- android的消息处理机制(图文+源码分析)—Looper/Handler/Message
- Android中使用WebSocket实现群聊和消息推送功能(不使用WebView)
- Android中通过Notification&NotificationManager实现消息通知
- Android消息处理机制Looper和Handler详解
- android开发教程之使用looper处理消息队列
- Android中使用socket通信实现消息推送的方法详解
- Android顶栏定时推送消息
- android使用NotificationListenerService监听通知栏消息
- 深入浅析Android消息机制
- android通过google api获取天气信息示例
- Android编程实现google消息通知功能示例