1

我想重定向到设备默认的谷歌地图应用程序。所以我使用一些参数调用波纹管 url,但优化参数不起作用。所以,任何人都知道如何在启动谷歌地图网址时应用优化假。

是输出网址。

String mapOptions = [  
   'origin=${widget.currentLocation.latitude.toString()}%2C${widget.currentLocation.longitude.toString()}',
      'destination=${(destinationAddress.replaceAll(',', '%2C')).replaceAll(' ', '%20')}',
      'destination_place_id=${widget.routeDeliveryDetail.deliveryList[widget.routeDeliveryDetail.deliveryList.length - 1].placeId}',
      'waypoints=$wayPoint',
      'waypoint_place_ids=$wayPointPLaceId',
      'optimization=true',
      'travelmode=driving'
    ].join('&');
    String googleUrl = 'https://www.google.com/maps/dir/?api=1&$mapOptions';
    print(googleUrl);
    try {
      if (await canLaunch(googleUrl)) {
        await launch(googleUrl);
      } else {
        throw 'Could not open the map.';
      }
    } catch (e) {
      print(e);
    }
4

1 回答 1

0

您必须将“optimize:true”作为航点参数中的第一个参数传递,以允许方向服务通过以更有效的顺序重新排列航点来优化提供的路线。

String mapOptions = [  
   'origin=${widget.currentLocation.latitude.toString()}%2C${widget.currentLocation.longitude.toString()}',
      'destination=${(destinationAddress.replaceAll(',', '%2C')).replaceAll(' ', '%20')}',
      'destination_place_id=${widget.routeDeliveryDetail.deliveryList[widget.routeDeliveryDetail.deliveryList.length - 1].placeId}',
      'waypoints=$wayPoint',
      'waypoint_place_ids=optimize:true|$wayPointPLaceId',
      'travelmode=driving'
    ].join('&');
    String googleUrl = 'https://www.google.com/maps/dir/?api=1&$mapOptions';
    print(googleUrl);
    try {
      if (await canLaunch(googleUrl)) {
        await launch(googleUrl);
      } else {
        throw 'Could not open the map.';
      }
    } catch (e) {
      print(e);
    }
于 2021-07-02T16:00:59.177 回答