将航点传递给GoogleMaps android以创建电路路线 [英] Create a circuit route by passing waypoints to GoogleMaps android

查看:264
本文介绍了将航点传递给GoogleMaps android以创建电路路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正致力于通过 Intent 路标到 Gmaps / code>,以便使用可以通过我发送的自定义航点导航到目的地



I当我在嵌入的 Google Maps 中绘制这条路线时,我可以看到 Circuit Circuit ,但是当我看到相同的路线时在 Gmaps 应用程序中, Circuit 已损坏。

我的代码:

 字符串srcAdd =saddr =+ latLngArrayList.get(0).latitude +  + latLngArrayList.get(0).longitude; 
String desAdd =& daddr =+ latLngArrayList.get(latLngArrayList.size() - 1).latitude +,+ latLngArrayList.get(latLngArrayList.size() - 1).longitude;
String wayPoints =;

for(int j = 1; j
wayPoints = wayPoints ++ to:+ latLngArrayList。得到(J).latitude + + latLngArrayList.get(J).longitude;
}

String link =https://maps.google.com/maps?+ srcAdd + desAdd + wayPoints;
final Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(link));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(com.google.android.apps.maps,com.google.android.maps.MapsActivity);
startActivity(intent);

线路



无线路由

解决方案

我建议看一看



Google地图网址链接对于这些路标是以下内容:





正如你所看到的,两条路线都是相同的,所以Directions API和Google Maps URL可以按照预期工作。我相信你应该改变你的代码以使用Google Maps URLs:

  String srcAdd =& origin =+ latLngArrayList .get(0).latitude +,+ latLngArrayList.get(0).longitude; 
String desAdd =& destination =+ latLngArrayList.get(latLngArrayList.size() - 1).latitude +,+ latLngArrayList.get(latLngArrayList.size() - 1).longitude;
String wayPoints =;

for(int j = 1; j wayPoints = wayPoints +(wayPoints.equals()?: %7C)+ latLngArrayList.get(j).latitude +,+ latLngArrayList.get(j).longitude;
}
wayPoints =& waypoints =+ wayPoints;

String link =https://www.google.com/maps/dir/?api=1&travelmode=driving+ srcAdd + desAdd + wayPoints;
final Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(link));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(com.google.android.apps.maps,com.google.android.maps.MapsActivity);
startActivity(intent);

另外,您可以使用 dir_action = navigate 参数,以便直接打开turn-by-turn导航。



我希望这有助于!


I am working on functionality where I send waypoints to Gmapsapp through Intent so that use can navigate to the destination by the custom waypoints that I send

I when I plot this route in my embedded Google Maps , I can see Circuit route , but when I see the same route in Gmapsapp , the Circuit is broken.

My code :

String srcAdd = "saddr="+latLngArrayList.get(0).latitude+","+latLngArrayList.get(0).longitude;
        String desAdd = "&daddr="+latLngArrayList.get(latLngArrayList.size() - 1).latitude+","+latLngArrayList.get(latLngArrayList.size() - 1).longitude;
        String wayPoints = "";

        for (int j = 1; j < latLngArrayList.size() - 1; ++j) {

            wayPoints =wayPoints+"+to:"+latLngArrayList.get(j).latitude+","+latLngArrayList.get(j).longitude;
        }

        String link="https://maps.google.com/maps?"+srcAdd+desAdd+wayPoints;
        final Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(link));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
        startActivity(intent);

circuit route

no circuit route

解决方案

I would suggest having a look at Google Maps URLs API that was launched in May 2017. This API provides a universal cross-platform links that you can use in your applications to launch intents for Google Maps. One of the supported modes is directions mode. You can read about it here:

https://developers.google.com/maps/documentation/urls/guide#directions-action

As you use Directions API and posted sample coordinates of waypoints, I was able to test the results in web service and in Google Maps URLs.

The web service results are tested in Directions calculator tool:

https://directionsdebug.firebaseapp.com/?origin=19.07598304748535%2C72.87765502929688&destination=19.07598304748535%2C72.87765502929688&waypoints=18.7284%2C73.4815%7C18.6876%2C73.4827%7C18.5839587%2C73.5125092%7C18.5369444%2C73.4861111%7C18.480567%2C73.491658

The route that we get via Directions API is the following

The Google Maps URLs link for these waypoints is the following

https://www.google.com/maps/dir/?api=1&origin=19.07598304748535,72.87765502929688&destination=19.07598304748535,72.87765502929688&waypoints=18.7284,73.4815%7C18.6876,73.4827%7C18.5839587,73.5125092%7C18.5369444,73.4861111%7C18.480567,73.491658&travelmode=driving

The route that you get using Google Maps URLs is shown in this screenshot

As you can see both routes are the same, so Directions API and Google Maps URLs work as expected. I believe you should change your code for intents to use Google Maps URLs:

String srcAdd = "&origin=" + latLngArrayList.get(0).latitude + "," + latLngArrayList.get(0).longitude;
String desAdd = "&destination=" + latLngArrayList.get(latLngArrayList.size() - 1).latitude + "," + latLngArrayList.get(latLngArrayList.size() - 1).longitude;
String wayPoints = "";

for (int j = 1; j < latLngArrayList.size() - 1; j++) {
    wayPoints = wayPoints + (wayPoints.equals("") ? "" : "%7C") + latLngArrayList.get(j).latitude + "," + latLngArrayList.get(j).longitude;
}
wayPoints = "&waypoints=" + wayPoints; 

String link="https://www.google.com/maps/dir/?api=1&travelmode=driving"+srcAdd+desAdd+wayPoints;
final Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(link));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

In addition, you can use dir_action=navigate parameter in order to open turn-by-turn navigation directly.

I hope this helps!

这篇关于将航点传递给GoogleMaps android以创建电路路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆