{"id":1346,"date":"2022-08-30T15:15:46","date_gmt":"2022-08-30T15:15:46","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/13\/error-with-new-google-maps-directionservice-on-google-maps-api-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:46","modified_gmt":"2022-08-30T15:15:46","slug":"error-with-new-google-maps-directionservice-on-google-maps-api-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/error-with-new-google-maps-directionservice-on-google-maps-api-collection-of-common-programming-errors\/","title":{"rendered":"Error with &ldquo;new google.maps.directionService()&rdquo; on google maps api-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m tryng to do a map with google maps api and jquery-mobile, the map I want to do it&#8217;s a directions map. I&#8217;ve two GPS coordinate and I wanto to show the way betwen the two points when the map is initialized. This is the code:<\/p>\n<pre><code> \n\n \n\n\n\n\n\n \n<\/code><\/pre>\n<p>and the code of the script is:<\/p>\n<pre><code>\n\nvar dirService;\n\nvar render;\n\nfunction calcolateRoute(){\n\n   dirService = new google.maps.directionService();\n\n   var myOrigin = new google.maps.LatLng( 46.448327,12.37707);\n\n   var myDestination = new google.maps.LatLng( 46.443993,12.388498)\n\n   var mapOptions = {\n\n  zoom:7,\n\n  mapTypeId: google.maps.MapTypeId.ROADMAP,\n\n  center: myOrigin};\n\n  var map = new google.maps.Map(document.getElementById(\"map_canvas\"), mapOptions);\n\n  var renderOpt = { map:map };\nrender = new google.maps.directionRenderer(renderOpt);\n\nvar requestRoute = {\n\n        origin: myOrigin,\n\n        destination: myDestination,\n\n        travelMode: google.maps.travelMode.BICYCLING};\n\ndirService.route(requestRoute, function(result, status){\n\nif(status == google.maps.DirectionsStatus.OK){\n\n    render.setDirection(result);                        \n\n}else{\n\n            alert('ERROR ');}\n\n});\n\n\n\n}\n \n<\/code><\/pre>\n<p>When the browser render the page i receive this error:<\/p>\n<pre><code>Uncaught TypeError: undefined is not a function\n<\/code><\/pre>\n<p>at the line<\/p>\n<pre><code>dirService = new google.maps.directionService();\n<\/code><\/pre>\n<p>I don&#8217;t understand why the script return the error&#8230;. Someone can help me? Sorry for my bad english!!<\/p>\n<ol>\n<li>\n<p>You are spelling the DirectionsService incorrectly<\/p>\n<p>Should be:<\/p>\n<pre><code>dirService = new google.maps.directionsService();\n<\/code><\/pre>\n<p>Not:<\/p>\n<pre><code>dirService = new google.maps.directionService();\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-13 09:48:32. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m tryng to do a map with google maps api and jquery-mobile, the map I want to do it&#8217;s a directions map. I&#8217;ve two GPS coordinate and I wanto to show the way betwen the two points when the map is initialized. This is the code: and the code of the script is: var dirService; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1346","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1346"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1346\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}