Problem:
I want to connect Google Map markers in a sequential line (A → B → C) without closing the loop back to the starting point (A).
Solution:
The issue arises when the last coordinate duplicates the first one, which closes the loop. The updated JavaScript provided ensures that if the first and last coordinates are identical, the last coordinate is removed to prevent the path from closing.
Here’s the corrected code snippet:
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) { if (markers.hasOwnProperty(marker)) { latLng = { 'lat': markers[marker].position.lat(), 'lng': markers[marker].position.lng() }; tripCoordinates.push(latLng); } } // Remove the last coordinate if it duplicates the first coordinate if (tripCoordinates.length > 1) { var firstCoord = tripCoordinates[0]; var lastCoord = tripCoordinates[tripCoordinates.length - 1]; if (firstCoord.lat === lastCoord.lat && firstCoord.lng === lastCoord
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.
This topic contains 1 reply, has 1 voice.
Last updated by 6 days, 7 hours ago.
Assisted by: Christopher Amirian.