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

  • SEARCH
  • Home
  • 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 7769779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:14:34+00:00 2026-06-01T16:14:34+00:00

How can I add a mouseover event listener to the directionsRenderer when using the

  • 0

How can I add a mouseover event listener to the directionsRenderer when using the DirectionsService?

I know how to add a listener to a straight line but can’t seem to find the object in the directionsRenderer.

For example this works:

function getStraightLine(coordinates) {
    if (progress.length == 0)
            progress = coordinates;
        else
            progress.push(coordinates[1]);
        updateDistance();
        var line = new google.maps.Polyline({
            path: coordinates,
            strokeColor: "#FF0000",
            strokeOpacity: .5,
            strokeWeight: 2,
            map: map
        });
        google.maps.event.addListener(line, 'mouseover', function(){
            alert("moused over straight line!");
        });
        return line;
    }

But this doesn’t:

function getDirectionsPath(coordinates) {
        var directionsPath = new google.maps.DirectionsRenderer();
        directionsPath.setMap(map);

        var request = {
            origin: coordinates[0],
            destination: coordinates[1],
            travelMode: google.maps.TravelMode.WALKING
        };

        directionsService.route(request, function (result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                var coordinates = result.routes[0].overview_path;
                if (progress.length == 0)
                    progress = coordinates;
                else
                    progress = progress.concat(coordinates);
                directionsPath.setDirections(result);
                google.maps.event.addListener(directionsPath, 'mouseover', function(){
                    alert("moused over straight line!");
                });
            }
        });

        return directionsPath;
    }

Instead of directionsPath I’ve tried result, result.routes[0], and a few others.

So what object should I use?

  • 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-01T16:14:35+00:00Added an answer on June 1, 2026 at 4:14 pm

    Will you use the ‘drag’ event on the ‘polyline’ that generated from the setDirections(directionsResult) method?

    If you don’t, I think you can create a ‘polyline’ by yourself like this:

    directionsService.route(request, function (result, status) 
    {
            var myRoute = result.routes[0].legs[0];
            if (status == google.maps.DirectionsStatus.OK) 
            {
                for (var i = 0; i < myRoute.steps.length; i++) {
                    for (var j = 0; j < myRoute.steps[i].lat_lngs.length; j++) {
                        points.push(myRoute.steps[i].lat_lngs[j]);
                    }
                }
            }
        drawRoute();
    }
    
    function drawRoute() 
    {
        var routLine = new google.maps.Polyline(
            {
                path: points,
                strokeColor: "Red",
                strokeOpacity: 0.5,
                strokeWeight: 10    
            }
        );
        routLine.setMap(mapCanvas);
    
        // Add a listener for the rightclick event on the routLine
        *google.maps.event.addListener(routLine, 'mouseover', function(){
                    alert("moused over straight line!");
                });*
    }
    

    if you have solved the problem use the method like google.maps.DirectionsRenderer().setDirections(result)?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know one can add event listener for window.error. However when working with Iframes,
I can add and remove the last line in my dynamic form and calculate
I can add a normal rightBarButton to my navigation without a problem but now
I can add a Conditional statement to a breakpoint, for instance arg0.startsWith(something) but i'd
We can add an image to an photo album using UIImage *img = [UIImage
I know I can add a icon to the Resources.resx file of a project
I know that I can add a HintPath to an external DLLs to help
Using the google maps API (v3) I can successfully add an array of markers
In flex, I am able to add mouseOver ( in mx:TextInput ) event as
I want to add a MouseOver event handler for any tag. Let say just

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.