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 9118949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:16:38+00:00 2026-06-17T05:16:38+00:00

This demo link DEMO with a sigle symbol I am showing points on google

  • 0

This demo link

DEMO with a sigle symbol

I am showing points on google map as above.

I want to compute the distance travelled along the path.

Not calculated by start and end point but by path of travel.

How to do this with google compute distance.

I used compute distance example

<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<style type="text/css">
    html {
        height: 100%
    }

    body {
        height: 100%;
        margin: 0px;
        padding: 0px
    }

    #map_canvas {
        height: 100%;
    }
</style>
<script type="text/javascript"
        src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false&v=3.3">
</script>
<script type="text/javascript">




    var g = google.maps;
    function initialize() {
        var latlng = new g.LatLng(62.397, 12.644);
        var myOptions = {
            zoom: 4,
            center: latlng,
            mapTypeId: g.MapTypeId.ROADMAP
        };
        var map = new g.Map(document.getElementById("map_canvas"), myOptions);
        registerMapDragHandler(map);
    }

    function registerMapDragHandler(aMap) {

        var map = aMap;

        g.event.addListener(map, 'click', function(event) {
            createLineBeingDragged(map, event.latLng);
        });

        function createLineBeingDragged(map, pos) {
            var line = new g.Polyline({map: map, path: [pos, pos]});
            g.event.addListener(map, 'mousemove', function(event) {
                line.getPath().setAt(1, event.latLng);
            });
            g.event.addListener(line, 'click', function(event) {
                g.event.clearListeners(map, 'mousemove');
                g.event.clearListeners(line, 'click');
                createMarkersForLine(map, line);
            });

            function createMarkersForLine(map, line) {
                var startMarker = createMarker(line, 0);
                var endMarker = createMarker(line, 1);
                startMarker.nextMarker = endMarker;
                endMarker.previousMarker = startMarker;
            }

            function createMarker(line, pathPos) {
                var position = line.getPath().getAt(pathPos);
                var marker = new g.Marker({map: map, position: position, visible: true, flat: true, draggable: true, raiseOnDrag: false});

                // Marker functions
                marker.getPathIndex = function() {
                    if (this.previousMarker != null) {
                        return this.previousMarker.getPathIndex() + 1;
                    } else {
                        return 0;
                    }
                }

                marker.startDrag = function(pos) {
                    if (!marker.previousMarker || !marker.nextMarker) {
                        line.getPath().insertAt(marker.getPathIndex(), pos);
                        var newMarker = createMarker(line, marker.getPathIndex());
                        if (marker.nextMarker) {
                            newMarker.previousMarker = marker;
                            newMarker.nextMarker = marker.nextMarker;
                            newMarker.nextMarker.previousMarker = newMarker;
                            marker.nextMarker = newMarker;
                        } else {
                            newMarker.nextMarker = marker;
                            newMarker.previousMarker = marker.previousMarker;
                            newMarker.previousMarker.nextMarker = newMarker;
                            marker.previousMarker = newMarker;
                        }
                    }
                }

                marker.beingDragged = function() {
                    line.getPath().setAt(marker.getPathIndex(), marker.getPosition());
                }

                // Listeners
                g.event.addListener(marker, 'dragstart', function(event) {
                    marker.startDrag(event.latLng);
                });

                g.event.addListener(marker, 'drag', function(event) {
                    marker.beingDragged();
                });

                g.event.addListener(marker, 'click', function(event) {
                    var length = g.geometry.spherical.computeLength(line.getPath()) / 1000;
                    var infoWindow = new g.InfoWindow(
                    {
                        content: "<ul><li>Line length: " + length.toFixed(2) + " km</li>"+
                                "<li>Latitude: " + marker.getPosition().lat().toFixed(6) + "</li>"+
                                "<li>Longitude: " + marker.getPosition().lng().toFixed(6) + "</ul>"
                    });
                    infoWindow.open(map, marker);
                });

                return marker;
            }
        }
    }
</script>

if I add the google library js for this example it gives error that multiple google libraries are loaded .

and if i not included this library it gives error that computeLength not defined.

I want to integrate the functionality of computing the distance to that Demo link i have provided..

Thanks

  • 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-17T05:16:40+00:00Added an answer on June 17, 2026 at 5:16 am

    This is your modified

    link to the demo

    You have to add the following to html

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false&v=3.3">
    

    and following to the javascript

    polyline = new google.maps.Polyline(polylineoptns);
    var length = google.maps.geometry.spherical.computeLength(polyline.getPath());
    alert(length);
    

    May this work for you..

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

Sidebar

Related Questions

This demo creates markers at random points on map: http://gmap3.net/examples/pan-to-markers.html Whats the smallest modification
I was testing out this demo on query-ui-maps: http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-mobile.html#directions_map Everything is the same except
I'm trying to insert a link after form elements to clear them. This demo
http://www.frostjedi.com/terra/scripts/demo/jquery02.html According to this link elements can be moved around by doing $('#container1').append($('#container2')). Unfortunately,
I have created this "shell" in jQuery: Code: link text Demo: link text I
I have the working demo is in this link . The markup is something
Please check out this example, first in FF, Chrome or Safari: [demo link removed]
I'm trying to follow the demo from this link to add a jqGrid to
I have put this simple malformed HTML into htmlpurifier demo page (link with my
http://jqueryfordesigners.com/demo/scroll-link-nav.html The link above is more or less what im looking for in terms

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.