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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:08:18+00:00 2026-06-12T23:08:18+00:00

I am trying to do some work with google maps and auto-complete . I

  • 0

I am trying to do some work with google maps and auto-complete . I have taken the google distance script and trying to integrate the autocomplete of google with it. The distance calculation and Routes Direction are working fine. But i failed for the autocomplete in start and end input field . If i manually type the location in both end and start field, it works, but no auto complete of google works.

<style type="text/css">
html {
    height: 100%
}
body {
    height: 100%;
    margin: 0px;
    padding: 0px
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
    //<![CDATA[
      var map = null;
      var directionDisplay;
      var directionsService = new google.maps.DirectionsService();

      function initialize() {
        directionsDisplay = new google.maps.DirectionsRenderer();
        var mapOptions = {
          zoom: 7,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          center: new google.maps.LatLng(41.850033, -87.6500523)
        };
        map = new google.maps.Map(document.getElementById('map_canvas'),
            mapOptions);
        directionsDisplay.setMap(map);
        directionsDisplay.setPanel(document.getElementById('directions-panel'));

        var control = document.getElementById('control');
        control.style.display = 'block';
        map.controls[google.maps.ControlPosition.TOP].push(control);
      }

      function calcRoute() {
        var start = document.getElementById('start').value;
        var end = document.getElementById('end').value;
        var request = {
          origin: start,
          destination: end,
          travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        directionsService.route(request, function(response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
            computeTotalDistance(response);
          }
        });
      }
      function computeTotalDistance(result) {
      var total = 0;
      var myroute = result.routes[0];
      for (i = 0; i < myroute.legs.length; i++) {
        total += myroute.legs[i].distance.value;
      }
      total = total / 1000.
      document.getElementById("total").innerHTML = total + " km";
      }

    function auto() {
    var input = document.getElementById[('start'), ('end')];
    var types
    var options = {
       types: [],
       componentRestrictions: {country: ["AUS"]}
        };
        var autocomplete = new google.maps.places.Autocomplete(input, options);
     }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>
<body onLoad="initialize()">
<div id="total"></div>
<div id="control"> <strong>Start:</strong>
<input type="text" id="start"><input type="text" id="end"><input type="button" value="GO" onClick="calcRoute();">
</div>
<table border="1" style="height:100%; width:100%;">
  <tr>
    <td style="width: 70%; height: 100%;"><div id="map_canvas" style="width:100%;height:100%;"></div></td>
    <td  style="width: 30%; height: 100%;"><div id="directions-panel" style="width:100%;height: 100%;"></div></td>
  </tr>
</table>
</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-12T23:08:19+00:00Added an answer on June 12, 2026 at 11:08 pm

    Change

         <script type="text/javascript"
         src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    

    To

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
    

    After

    map = new google.maps.Map(document.getElementById('map_canvas'),
            mapOptions);
    

    Add

        //Find From location    
        var fromText = document.getElementById('start');
        var fromAuto = new google.maps.places.Autocomplete(fromText);
        fromAuto.bindTo('bounds', map);
        //Find To location
        var toText = document.getElementById('end');
        var toAuto = new google.maps.places.Autocomplete(toText);
        toAuto.bindTo('bounds', map);
        //  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get some auto complete to work. I have this URL i
I'm trying to work with the google maps API and am having some trouble.
I'm trying to generate some HTML content for a google maps infowindow. I have
I'm trying to integrate some Google maps bits into my Java web app using
Ive been trying to solve some issues for implementing google maps with the api
I am trying to do some work with Google Calendar on Java. So I
I've been trying to work with the Google Calendar JSON API, but have been
I'm trying to prototype some plotting on Google Maps API. I've followed the code
I'm trying to place some text and form elements into a Google Maps InfoWindow
I'm trying to implement some Google Maps stuff in .NET for a uni project.

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.