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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:26:07+00:00 2026-06-16T13:26:07+00:00

I have a bit of difficulty to clear the data from the Google Maps

  • 0

I have a bit of difficulty to clear the data from the Google Maps API after someone issues a new request for directions.

Let me explain the situation: A user comes to the site and decides to get the route to our location. The user fills in the location where he or she is right now. The user gets the data just fine, but the problem is that when he/she enters a new location the old directions stay in the panel. I figured out that to clear it you can use this line of code.

directionsDisplay.setPanel(null);

The problem I have with this, is that I can’t figure out where to place it within the code(yes I am new to js).

Here is what I have so far:

function calculateDirections(locFrom, locTo) {
    var directionsDisplay = new google.maps.DirectionsRenderer();
    var directionsService = new google.maps.DirectionsService();
    var mapContainer = $('#contactInfo');
    var mapPanel = $('#mapPanel');
    var request = {
        origin: locFrom,
        destination: 'Address 01, City',
        travelMode: google.maps.TravelMode.DRIVING
    };
    var myOptions = {
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: locFrom
    };

    directionsService.route(request, function(result, status) {
        if(status == google.maps.DirectionsStatus.OK) {
            // Build frame
            var map = new google.maps.Map(document.getElementById('maps'), myOptions);  
            directionsDisplay.setPanel(document.getElementById("mapPanel"));
            directionsDisplay.setDirections(result);
            directionsDisplay.setMap(map);
            $('#contactInfo').css('top', '30px');
            $('#contactInfo').css('padding-bottom', '15px');
        }
        else {
            alert('Could not calculate route');
        }
    });
}

I figured, I would start with the directionsDisplay.setPanel(null); and after that load the data, so that in each iteration you start with clearing the data. However i am in over my head with this assignment. Help would be much appreciated.

EDIT:

For the record, the application has 1 fixed point(The location of our business) and the locFrom is the location from the user(this can be anywhere).

EDIT:

Here is the markup:

<div id="maps"></div>
   <div id="menu">
    <div class="contentWrapperLeft"></div>
    <div id="contactInfoRoute">
        <h2>Route</h2>          
                <input type="text" name="street" id="street" rel="Straat">
        <input type="text" name="place" id="place" rel="Plaats">
        <input type="button" name="submit" id="submit" value="Route">
    </div>

        <div id="contactInfo"> 
            <div id="mapPanel"></div>
            <p>Address 01 <br /> City, Country</p> 
        </div>
    </div>
  • 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-16T13:26:08+00:00Added an answer on June 16, 2026 at 1:26 pm

    The solution I came up with is as follows:

    What i did was to write an empty mapPanel div before the request was
    made like this:

    mapPanel.html('');
    

    I put this line above the variable ‘map’ and that made it work without any problems.

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

Sidebar

Related Questions

I have a bit of difficulty creating some tables in a specific order from
I am having a bit of difficulty with this current code I have set
Have a bit of confusion here. I added a few objects from a class
I have a bit of code that fits theoretical prediction to experimental data, and
I have a bit difficulty to explain this question in a simple way, so
having difficulty with a bit of code I have. I think variables are stuck
I currently have a script parsing data from a Web Service, all examples I've
I am having a bit of difficulty working something out. I have the follow
I'm having a bit of difficulty setting a variable from the code behind and
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:

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.