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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:44:31+00:00 2026-06-13T08:44:31+00:00

I have a JavaScript postcode search that searches for the 3 closet stores in

  • 0

I have a JavaScript postcode search that searches for the 3 closet stores in the UK depending on what is entered into the input. At the moment it finds the 3 stores fine.

Firstly, I want to drop a marker at the postcode entered in the input.

Secondly, when the three results show up, they are marked on the map. I want to have a link called directions that, once clicked, will show directions from the start to the chosen store.

I have tried the following code but it doesn’t work…however it does get the postcode data from the input and from the directions link and shows them in the console. Will I need to convert them into long and lat for it to work?

function calcRoute() {
    var start = document.getElementById('address').value;
    var end = document.getElementById('get-directions').name;
    //console.log(start, end)
    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);
      }
    });
  }

I have this code for my start marker, but this doesn’t seem to work either

function initialize() {
    var start_marker = new google.maps.LatLng(document.getElementById('address').value);
    directionsDisplay = new google.maps.DirectionsRenderer();
    var mapOptions = {
      zoom:7,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: start_marker
    }
    marker = new google.maps.Marker({
          map:map,
          draggable:false,
          animation: google.maps.Animation.DROP,
          position: start_marker,
        });
    map = new google.maps.Map(document.getElementById('map'), mapOptions);
    directionsDisplay.setMap(map);
  }

This part gets the long/lat data from the postcode,

this.geocode = function(address, callbackFunction) {
  geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      var result = {};
      result.latitude = results[0].geometry.location.lat();
      result.longitude = results[0].geometry.location.lng();
      callbackFunction(result);
      //console.log(result);
        //console.log("Geocoding " + geometry.location + " OK");
        addMarker(map, results[0].geometry.location);
    } else {
      alert("Geocode was not successful for the following reason: " + status);
      callbackFunction(null);
    }
  });

And the function for the addMarker is here:

function addMarker(map, location) {

console.log("Setting marker for (location: " + location + ")");
marker = new google.maps.Marker({
map : map,
animation: google.maps.Animation.DROP,
position : location
});

}

Any help would be greatly appreciated!

  • 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-13T08:44:32+00:00Added an answer on June 13, 2026 at 8:44 am

    The constructor for a google.maps.LatLng requires two floating point numbers as arguments, not a string:

    var start_marker = new google.maps.LatLng(document.getElementById('address').value);
    

    If all you have is an address, you need to use the Geocoding service to retrieve coordinates for that address if you want to display a marker on the map.

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

Sidebar

Related Questions

I have JavaScript that outputs links (search results) but I'm having problems adding onclick
I have used Javascript to enable or disable a button, depending on the input
I have JavaScript that takes the entry from a form and then searches the
I have javascript that working fine in Firefox 3.x.x, but it does not work
I have Javascript that opens another window and registers a click handler for all
I have JavaScript that is doing activity periodically. When the user is not looking
I have JavaScript code which copies the value of input file and paste it
I have javascript string variable with var sttr=We prefer questions that can be answered
I am creating a site for Wordpress and I have installed a postcode search
Possible Duplicate: JavaScript: string contains I have a postcode variable and want to use

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.