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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:58:27+00:00 2026-06-15T15:58:27+00:00

i’m having a problem translating the already working directions script in v2 to v3.

  • 0

i’m having a problem translating the already working directions script in v2 to v3.
the error is the tohere/fromhere function which is not correctly executed.

the marker is displayed correctly, after the first click the infowindow opens.
when i’m then clicking “tohere” or “fromhere” it throws error “tohere is not defined”…

any hints what i’m doing wrong?

jQuery(document).ready(function () {

if (jQuery('#map_canvas').length) {
initActive();
}


function initialize(lat, long,html) {
var latid = lat;
var longit = long;
var myLatlng = new google.maps.LatLng(latid, longit);
//var myLatlng = new google.maps.LatLng(51.512098,-0.137692);
var myOptions = {
    zoom:17,
    navigationControl:true,
    mapTypeControl:false,
    scaleControl:false,
    scrollwheel:false,
    disableDefaultUI:true,
    disableDoubleClickZoom:true,
    center:myLatlng,
    mapTypeId:google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var styles = [
    {
        stylers:[

            { saturation:-100 }
        ]
    }
];

map.setOptions({styles:styles});

var myLatLng = new google.maps.LatLng(latid, longit);
var marker = createMarker(map,myLatLng,html);
}

function initActive() {
var flat = jQuery('#map_canvas').data('coord-lat');
var flong = jQuery('#map_canvas').data('coord-lon');
var title = jQuery('#map_canvas').data('content');
initialize(flat, flong,title);
}   


function createMarker(map, latlng,html) {
var marker = new google.maps.Marker({
    position: latlng,
    map: map
    });

var infowindow = new google.maps.InfoWindow({ size: new google.maps.Size(150,50)});
marker.setIcon("mapIcons/marker_red.png");




    var gmarkers = []; 
    var to_htmls = [];
    var from_htmls = [];
    var htmls = [];
    var i = gmarkers.length;

    // The info window version with the "to here" form open
    to_htmls[i] = html + '<br>Directions: <b>To here<\/b> - <a href="javascript:fromhere(' + i + ')">From here<\/a>' +
       '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
       '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
       '<INPUT value="Get Directions" TYPE="SUBMIT">' +
       '<input type="hidden" name="daddr" value="' + latlng.lat() + ',' + latlng.lng() + 
              // "(" + name + ")" + 
       '"/>';
    // The info window version with the "to here" form open
    from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')">To here<\/a> - <b>From here<\/b>' +
       '<br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
       '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
       '<INPUT value="Get Directions" TYPE="SUBMIT">' +
       '<input type="hidden" name="saddr" value="' + latlng.lat() + ',' + latlng.lng() +
              // "(" + name + ")" + 
       '"/>';
    // The inactive version of the direction info
    html = html + '<br>Directions: <a href="javascript:tohere('+i+')">To here<\/a> - <a href="javascript:fromhere('+i+')">From here<\/a>';
    var contentString = html;

    google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(contentString); 
    infowindow.open(map,marker);
    });

    gmarkers.push(marker);
    htmls[i] = html;
}


// functions that open the directions forms
function tohere(i) {
 infowindow.setContent(to_htmls[i]); 
}
function fromhere(i) {
  infowindow.setContent(from_htmls[i]); 
}


}); //documentready close
  • 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-15T15:58:28+00:00Added an answer on June 15, 2026 at 3:58 pm

    All your code is local to the jQuery(document).ready function, so is not available in the global context where HTML click handlers run. Move the function declarations outside of that function.

    Looks like your v2 code came from Mike Williams’ v2 tutorial. This example of his “Getting Directions” map which I ported to v3, may help you.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have an autohotkey script which looks up a word in a bilingual dictionary
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.