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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:23:58+00:00 2026-06-05T19:23:58+00:00

I am trying to get the distance between two location using Google Mps API

  • 0

I am trying to get the distance between two location using Google Mps API following this post. I also found the following example.

I have integrated the same code and but I don’t see any results. What am I doing wrong here?

Can anyone please let me know of any links where the examples have been indicated for Google Maps APIv3?

  <html>
  <head>
  <style>
  h1{
      font-family:arial,helvetica,sans-serif;
      font-size:20px;
      font-weight:bold;
  }
  p{
      font-family:arial,helvetica,sans-serif;
  }
  </style>
  <script include="/home/rajeev/Desktop/ge/jquery-1.7.2.js"></script>
  <script>
  var map;
      var marker, marker2;
      function initialize() {
          var mapDiv = document.getElementById('map-canvas');
          map = new google.maps.Map(mapDiv, {
              center: new google.maps.LatLng(-36.86501268451408, 174.723858833313),
              zoom: 16,
              mapTypeId: google.maps.MapTypeId.ROADMAP
          });
      }

      $(function() {
          initialize();

         var geocoder = new google.maps.Geocoder();

         //Geocode the first address
         geocoder.geocode({
            address : '27 West View Road Westmere Auckland New Zealand',
            region: 'no'
         }, function(results, status){
            //Create the first marker
            marker = new google.maps.Marker({
                position: new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()),
                map: map,
            });

            //Now geocode the second address
            geocoder.geocode({
              address : '37 Old Mill Road Westmere Auckland New Zealand',
              region: 'no'
            }, function(results, status){
              //Create the second marker
              marker2 = new google.maps.Marker({
                  position: new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()),
                  map: map,
              });

              //Now create the line (we have both markers at this point guaranteed)
              var line = new google.maps.Polyline({
                path: new Array(marker.getPosition(),marker2.getPosition()),
                strokeColor: '#ff0000',
                strokeOpacity: 1.0,
                strokeWeight: 2
              });

              line.setMap(map);

              //Now calculate the distance
              var R = 6371; // km
              var dLat = (marker.getPosition().lat() - marker2.getPosition().lat()).toRad();
              var dLon = (marker.getPosition().lng()- marker2.getPosition().lng()).toRad();
              var lat1 = marker2.getPosition().lat().toRad();
              var lat2 = marker.getPosition().lat().toRad();
              var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
              var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
              var distance = Math.ceil(R * c * 1000);
                $('p').html('The distance between the two addresses is:' + distance +'m');  
            });
         });
      });

    if (typeof(Number.prototype.toRad) === "undefined") {
      Number.prototype.toRad = function() {
        return this * Math.PI / 180;
      }
    }


  </script>
  </head>
  <body>

  <h1>Distance polyline between two street addresses</h1>
  <hr/>
  <p>
      </p>
  <hr/>
  <div id="map-canvas" style="width:500px;height:500px"></div>
  </body>
  • 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-05T19:24:00+00:00Added an answer on June 5, 2026 at 7:24 pm

    This is not correct

    <script include="/home/rajeev/Desktop/ge/jquery-1.7.2.js"></script>
    

    use

    <script src="/home/rajeev/Desktop/ge/jquery-1.7.2.js"></script>
    

    Also, include Google Maps API

    <script src="http://maps.google.com/maps/api/js?sensor=false&.js"></script>
    

    You can also use jQuery from Google CDN

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to calculate the distance between two places user Core Location. I've found
Trying to get my mind around google protobuf. I found some implementation of protobuf
I'm trying to calculate the distance between two points. The two points I stored
In the program below, I am trying to calculate the distance between two points.
I'm trying to measure the distance between two points (longitude, latitude). My problem is
Trying to work out distance between two points (lat & lng) I have an
I am trying to get the distance between my character and the ground, I
I encounter some issues on trying to calculate distance between one location and a
Hai am trying to get the gps location using BroadCast Receiver.its working fine,But i
I'm trying to find the distance between two points (for which I've latitudes &

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.