我的应用程序需要显示谷歌地图方向从A到B,但我不想把谷歌地图到我的应用程序-相反,我想用一个意图启动它。这可能吗?如果是,怎么做?
当前回答
试试这个
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+src_lat+","+src_ltg+"&daddr="+des_lat+","+des_ltg));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
其他回答
这对我来说很管用:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://maps.google.co.in/maps?q=" + yourAddress));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
试试这个
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+src_lat+","+src_ltg+"&daddr="+des_lat+","+des_ltg));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
对于多个路径点,也可以使用以下方法。
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://www.google.com/maps/dir/48.8276261,2.3350114/48.8476794,2.340595/48.8550395,2.300022/48.8417122,2.3028844"));
startActivity(intent);
第一组坐标是你的起始位置。接下来的所有点都是路径点,都是经过的路线。
只要在末尾连接“/latitude,longitude”来继续添加路径点。根据谷歌文档,显然有23个路径点的限制。不确定这是否也适用于Android。
Uri uri = Uri.parse("google.navigation:q=" + Latitude + "," + longitude + "&mode=d");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
你可以通过这种方式在Android上启动谷歌地图方向
btn_search_route.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String source = et_source.getText().toString();
String destination = et_destination.getText().toString();
if (TextUtils.isEmpty(source)) {
et_source.setError("Enter Soruce point");
} else if (TextUtils.isEmpty(destination)) {
et_destination.setError("Enter Destination Point");
} else {
String sendstring="http://maps.google.com/maps?saddr=" +
source +
"&daddr=" +
destination;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(sendstring));
startActivity(intent);
}
}
});
推荐文章
- 如何在java中格式化持续时间?(如格式H:MM:SS)
- urlencoder .encode(字符串)已弃用,我应该使用什么代替?
- javax.transaction.Transactional vs . org.springframework.transaction.annotation.Transactional
- Java 8接口方法中不允许“同步”的原因是什么?
- 如何找到Java堆大小和内存使用(Linux)?
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 谷歌地图API v3:我可以setZoom后fitBounds?
- 使用Enum实现单例(Java)
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- RabbitMQ与通道和连接之间的关系