Skip Navigation

[Resolved] Markers as waypoints showing path of a trip

This thread is resolved. Here is a description of the problem and solution.

Problem:
Markers as waypoints showing path of a trip

Solution:
To draw the path to map, you should try to add the following code to your view's JS box.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/markers-as-waypoints-showing-path-of-a-trip/#post-1333481

Relevant Documentation:
=> https://developers.google.com/maps/documentation/javascript/examples/polyline-simple

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 3 voices.

Last updated by Kristian Adolfsson 5 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1333267
image.png

Hello,
doing a web for a travel agency, they organize road trip vacations.
With Toolset Maps I am easily able to list all the waypoints in a map, but is it possible to show road connections between these markes? (as shown in the picture attached - blue line between markers).
Thanks in advance,
Tom

#1333481

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To draw the path to map, you should try to add the following code to your view's JS box:

<jQuery(document).ready(function($){
function initMap() {
  var mapid = 'map-2';
  var map = WPViews.view_addon_maps.get_map(mapid);
  var markers = WPViews.view_addon_maps.markers[mapid];
  if(markers.length == 0)
    return;
  var tripCoordinates = [];
  var latLng;
  // loop over all the markers and create an array of lat lng objects
  for(var marker in markers){
    latLng = {
      'lat':markers[marker].position.lat(),
      'lng':markers[marker].position.lng()
    };
    tripCoordinates.push(latLng);
  }
  // create a new polyline using the coordinates array, and add it to the map
  var tripPath = new google.maps.Polyline({
    path: tripCoordinates,
    geodesic: true,
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 2
  });
  tripPath.setMap(map);
} 
$( document ).on('js_event_wpv_addon_maps_init_map_completed', function( event, event_settings ) {
initMap();
} );
   
} );

Where:
- Change "map-2" with your original map ID, and change the trippath attributes to style the line.
=> hidden link

#1333671

Cooooool! Thanks very much!

#1334853

Worked like a charm!!
BUT, how do I decide the order they are drawn in?