HELP!! uncaught reference error

2,499 views
Skip to first unread message

Lewis Rogers

unread,
Feb 5, 2011, 1:46:34 PM2/5/11
to google-map...@googlegroups.com
Im having some difficulty creating a custom javascript map which displays the distance and start and end points as text as well as showing a visual display of the route. Im very new to the map api and javascript in general. I have used the debugging tools in chrome but cant work out where im going wrong. my code looks like this:

<!DOCTYPE html>
<html>
<head>
<title>Get Quote-ASTAR</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
 html { height: 100%; }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas{height 100%;}
</style>
<script type="text/javascript"
</script>
<script type="text/javascript">
 

  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map; 


function initialize() {
    var Halkyn = new google.maps.LatLng(53.231934, -3.186722);
    var myOptions = {
      zoom: 8,
      center: Halkyn,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
       
       
        map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);directionsDisplay.setMap(map);
  }


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);
var route = response.routes[0];
var summaryPanel= document.getElementById("directions_panel");




 summaryPanel.innerHTML = "";
        // For each route, display summary information.
        for (var i = 0; i < route.legs.length; i++) {
          var routeSegment = i + 1;
          summaryPanel.innerHTML += "<b>Route Segment: " + routeSegment + "</b><br />";
          summaryPanel.innerHTML += route.legs[i].start_address + " to ";
          summaryPanel.innerHTML += route.legs[i].end_address + "<br />";
          summaryPanel.innerHTML += route.legs[i].distance.text + "<br /><br />";
        }
      }
    });
  



</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="float:left;width:70%;height:100%;"></div>
   <div id="control_panel" style="float:right;width:30%;text-align:left;padding-top:20px"> 
   <div style="margin:20px;border-width:2px;"> 


<b>Start:</b> 
<select id="start"> 
  <option value="Chester,England, UK">Chester, UK</option> 
  <option value="Leeds,England, UK">Leeds, UK</option> 
</select>

<br />

<b>End:</b> 
<select id="end"> 
  <option value="Manchester,England UK"> Manchester,UK</option> 
  <option value="Shropshire,England,UK">Shropshire, UK</option> 
  <option value="Cardiff,Wales,UK">Cardiff,UK</option> 
  <option value="London, England,UK">London, UK </option> 
</select> 

<br /> 
  <input type="submit" onclick="calcRoute();" /> 
</div> 
<div id="directions_panel" style="margin:20px;background-color:#FFEE77;"></div> 
</div> 

</body>
</html>

I have the following errors:


  1. map.html:45Uncaught ReferenceError: start is not defined
    1. (anonymous function)map.html:45
  1. map.html:32Uncaught ReferenceError: directionsDisplay is not defined
    1. initializemap.html:32
    2. (anonymous function)map.html:80
    3. onload

Any help at all would be greatly appreciated. 

Thank you,
 Lewis.



Lewis Rogers

unread,
Feb 5, 2011, 2:22:30 PM2/5/11
to google-map...@googlegroups.com
Also this is a temporary link. Sorry for not including it. I did not read the "before posting article" oooops.



 Once again thank you for any help or advice that you can provide. 

Lewis.

geoco...@gmail.com

unread,
Feb 5, 2011, 2:37:32 PM2/5/11
to Google Maps JavaScript API v3
On Feb 5, 11:22 am, Lewis Rogers <iamroger...@gmail.com> wrote:
> Also this is a temporary link. Sorry for not including it. I did not read
> the "before posting article" oooops.
>
> http://pastehtml.com/view/1d3v6g0.html

Have you investigated your javascript errors?

I get:
Line: 46
Error: 'start' is undefined

Line: 33
Error: 'directionsDisplay' is undefined

you have a global: var directionDisplay; did you intend to use that?
It probably needs to be initialized to a DirectionsRenderer at some
point to be useful.

-- Larry

Paulo Fernandes

unread,
Feb 5, 2011, 2:42:44 PM2/5/11
to google-map...@googlegroups.com
You are closing the calcRoute function before it end

Remove the } before request variable

Next time, post a link for your website

> 1.
> map.html:45<file:///C:/Documents%20and%20Settings/Lewis/Desktop/map.html>Uncaught


> ReferenceError: start is not defined

> 1. (anonymous
> function)map.html:45<file:///C:/Documents%20and%20Settings/Lewis/Desktop/map.html>
>
>
> 1.
> map.html:32<file:///C:/Documents%20and%20Settings/Lewis/Desktop/map.html>Uncaught


> ReferenceError: directionsDisplay is not defined

> 1.
> initializemap.html:32<file:///C:/Documents%20and%20Settings/Lewis/Desktop/map.html>
> 2. (anonymous
> function)map.html:80<file:///C:/Documents%20and%20Settings/Lewis/Desktop/map.html>
> 3. onload


>
>
> Any help at all would be greatly appreciated.
>
> Thank you,
> Lewis.
>
>
>

> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To post to this group, send email to google-map...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-maps-js-a...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>

--
Sent from my mobile device

Paulo Fernandes
http://www.google.com/profiles/paulofernandesjr
http://twitter.com/paulofernandesj
+55 11 9797-5974

Lewis Rogers

unread,
Feb 7, 2011, 8:56:58 AM2/7/11
to Google Maps JavaScript API v3
Hi,

Thanks for responding so quickly. I have removed the } request before
the request variable but the map will not display at all. I will be
starting from scratch i think as it will be much more useful to find
out where exactly it is i am going wrong. A large portion of this code
was taken form the example "directions service way points". I want a
similar application, but without the way points. I need an application
that will display the calculation as text. Thanks for the help once
again.

Lewis.

On Feb 5, 7:42 pm, Paulo Fernandes <paulofernande...@gmail.com> wrote:
> You are closing the calcRoute function before it end
>
> Remove the } before request variable
>
> Next time, post a link for your website
>

Andrew Leach

unread,
Feb 7, 2011, 9:13:04 AM2/7/11
to google-map...@googlegroups.com
On 7 February 2011 13:56, Lewis Rogers <iamro...@gmail.com> wrote:
> Thanks for responding so quickly. I have removed the } request before
> the request variable but the map will not display at all.

There were the right number of } before you removed it, as there were
no syntax errors reported, but the one you removed was definitely in
the wrong place. That means that there should now be another one
inserted somewhere.

What's happening now is that there is one more { than the number of }
and the browser is signalling a syntax error.

If your indentation is consistent you may be able to find where the
new } should be added, otherwise you may have to resort to a printed
listing and coloured marker pens to work out the pairing.

geoco...@gmail.com

unread,
Feb 7, 2011, 11:45:40 AM2/7/11
to Google Maps JavaScript API v3
On Feb 7, 5:56 am, Lewis Rogers <iamroger...@gmail.com> wrote:
> Hi,
>
> Thanks for responding so quickly. I have removed the } request before
> the request variable but the map will not display at all. I will be
> starting from scratch i think as it will be much more useful to find
> out where exactly it is i am going wrong.

http://www.geocodezip.com/LewisRogers_mapA.html

-- Larry
> > >     src="http://maps.google.com/maps/api/js?sensor=false®ion=GB">
> > > map.html:45<file:///C:/Documents%20and%20Settings/Lewis/Desktop/map.html>Un­caught
> > >    ReferenceError: start is not defined
> > >    1. (anonymous
> > > function)map.html:45<file:///C:/Documents%20and%20Settings/Lewis/Desktop/ma­p.html>
>
> > >    1.
> > > map.html:32<file:///C:/Documents%20and%20Settings/Lewis/Desktop/map.html>Un­caught
> > >    ReferenceError: directionsDisplay is not defined
> > >    1.
> > > initializemap.html:32<file:///C:/Documents%20and%20Settings/Lewis/Desktop/m­ap.html>
> > >       2. (anonymous
> > > function)map.html:80<file:///C:/Documents%20and%20Settings/Lewis/Desktop/ma­p.html>
> > >       3. onload
>
> > > Any help at all would be greatly appreciated.
>
> > > Thank you,
> > >  Lewis.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Google Maps JavaScript API v3" group.
> > > To post to this group, send email to google-map...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > google-maps-js-a...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
> > --
> > Sent from my mobile device
>
> > Paulo Fernandeshttp://www.google.com/profiles/paulofernandesjrhttp://twitter.com/pau...
> > +55 11 9797-5974- Hide quoted text -
>
> - Show quoted text -

Lewis Rogers

unread,
Feb 7, 2011, 1:19:59 PM2/7/11
to google-map...@googlegroups.com
WOW! Truley wow. The support I have received from this group has been absolutely amazing! thank you so much for all your help. Thank you Larry for correcting the problem and a thank you to Andrew and Paulo for the suggestions. You have all made my day :)

Lewis.

Chris Broadfoot

unread,
Feb 8, 2011, 12:35:50 AM2/8/11
to google-map...@googlegroups.com
On Tue, Feb 8, 2011 at 5:19 AM, Lewis Rogers <iamro...@gmail.com> wrote:
WOW! Truley wow. The support I have received from this group has been absolutely amazing! thank you so much for all your help. Thank you Larry for correcting the problem and a thank you to Andrew and Paulo for the suggestions. You have all made my day :)

+1. You really get legendary support from these guys when you provide a link ;)


--
http://twitter.com/broady
Reply all
Reply to author
Forward
0 new messages