Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:42:04+00:00 2026-06-04T04:42:04+00:00

A polyline is already been drawn a map, but how can markers be placed

  • 0

A polyline is already been drawn a map, but how can markers be placed on it?

Current code:

map = new google.maps.Map(document.getElementById("map-canvas-tour"), mapOptions);

loadShowDates();

var polyFutureOptions = {
    path: pathFutureCoordinates,
    strokeColor: '#0000FF',
    strokeOpacity: 0.8,
    strokeWeight: 2.5
};

var polyPastOptions = {
    path: pathPastCoordinates,
    strokeColor: '#FF0000',
    strokeOpacity: 0.6,
    strokeWeight: 2.5
};

pathPast = new google.maps.Polyline(polyPastOptions);
pathFuture = new google.maps.Polyline(polyFutureOptions);
pathPast.setMap(map);
pathFuture.setMap(map);
infowindow = new google.maps.InfoWindow();
map.fitBounds(bounds);

There are two sets of points: pathFutureCoordinates and pathPastCoordinates and these refer to gigs in the past and gigs in the future all on a tour route (polyline). Each set of markers could be a different color.

What would I use to do this please?

Any other tips? A custom marker would be ideal.

Site page in question: http://goo.gl/H995E

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:42:05+00:00Added an answer on June 4, 2026 at 4:42 am

    Here’s a page where markers are placed either to extend the single polyline (click on the map), or when a spot in the polyline is clicked, a marker is added to the polyline. You can check if the new marker was correctly placed by dragging it and seeing the line adjust the segments.

    https://files.nyu.edu/hc742/public/googlemaps/distance2.html

    I’m not sure if you are planning to add new markers on the line by clicking or not. I will describe how the markers are added with clicks in the page above. Having a pre-built list of LatLngs would be a lot simpler (you only need steps 3 and 4 below).

    1. Add listener to detect clicks on the line (the line is made thick to aid in clicking)
    2. Figure out which segment of the line was clicked
    3. Add the marker to an array of markers, placing it in the right position (order, based on which markers the new one are surrounding it)
    4. Redraw the line using the new array of marker LatLngs.

    A click listener is added to the line.

      google.maps.event.addListener(line, 'click', function(event) {
          for (var i = 0 ; i < markers.length - 1; i++) {
            if(isPointOnSegment(markers[i].getPosition(),
               markers[i+1].getPosition(),event.latLng)) {
              addMarker(event.latLng, i+1);
              break;
            } 
          }
        });
      }
    

    Because we need to know which segment was clicked, a helper function is called (isPointOnSegment)

      function isPointOnSegment(gpsPoint1, gpsPoint2, gpsPoint ){
    
        //Provided by Engineer
        // http://stackoverflow.com/questions/10018003/which-segment-of-a-polyline-was-clicked
        // 1st version, ignores perfectly horiz and vert. lines
        var p1 = map.getProjection().fromLatLngToPoint( gpsPoint1 );
        var p2 = map.getProjection().fromLatLngToPoint( gpsPoint2 );
        var p = map.getProjection().fromLatLngToPoint( gpsPoint );
    
        var t_x = (p.x - p1.x)/(p2.x-p1.x);
        var t_y = (p.y - p1.y)/(p2.y-p1.y);
        return ( eq(t_x,t_y) && t_x >= 0 && t_x <= 1 && t_y >= 0 && t_y <= 1);
      } 
    

    Add marker and update marker position array:

        function addMarker(pos, where) {
    
        var marker = new google.maps.Marker({
          map: map,
          position: pos,
          draggable: true
        });
    
        markers.splice(where,0,marker); 
        drawPath();
       }
    

    Finally, redraw the line

      function drawPath() {
        countMarkers();
        var coords = [];
        for (var i = 0; i < markers.length; i++) {
          coords.push(markers[i].getPosition());
        }
        line.setPath(coords);
      }
    

    For adding markers where there are pre-existing coordinates

    http://jsfiddle.net/WZqgE/1/

      var pathFutureCoordinates = [
        new google.maps.LatLng(40, -80),
        new google.maps.LatLng(38, -85),
        new google.maps.LatLng(39, -92),
        new google.maps.LatLng(42, -98),
        new google.maps.LatLng(37, -102)      
      ];
      for (var i = 0; i < pathFutureCoordinates.length; i++) {
        new google.maps.Marker({
          map: map,
          position: pathFutureCoordinates[i],
          icon: "http://maps.google.com/mapfiles/kml/pal4/icon39.png"
        });
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a google map displaying a polyline. I can detect mouseover events for
I have some C# code that decodes map paths encoded using Google's polyline algorithm
I'm using google maps' Interactive Polyline Encoder Utility to plot locations on a map.
I need help with Google Maps Polyline I just downloaded this code ( just
I am trying to draw a geodesic polyline with Google Maps JavaScript API from
I can write my code logic to either buffer a polyline or to buffer
For Google Maps V3, I have some code that created a marker when a
I've been using Google Maps Api for a while and I recently checked that
I'm actually trying to render an encoded polyline obtained from the Google Map Directions
I'm using this function to add a new marker (and polyline) to a map:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.