{"id":526,"date":"2022-08-30T15:02:49","date_gmt":"2022-08-30T15:02:49","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/uncaught-type-error-can-not-read-property-latitude-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:49","modified_gmt":"2022-08-30T15:02:49","slug":"uncaught-type-error-can-not-read-property-latitude-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/uncaught-type-error-can-not-read-property-latitude-collection-of-common-programming-errors\/","title":{"rendered":"Uncaught Type Error: Can not read property latitude-Collection of common programming errors"},"content":{"rendered":"<p>This is part of a function I have written<\/p>\n<pre><code>                watchlocation: function() {\n            console.log(\"watchlocation Started\");\n            if (watchProcess == null) {\n                watchProcess = navigator.geolocation.watchPosition(locationcheck.handle_geolocation_query_success, locationcheck.handle_errors, {enableHighAccuracy:true});\n            }                       \n              if(position.coords.latitude == null) {\n                  var Lat = '52.5960';\n                  console.log(\"latitude Set Manually\");\n              }\n              else {\n                  var Lat = position.coords.latitude;\n                  console.log(\"latitude Set Automatically\");                         \n              };\n\n              if(position.coords.longitude == null) {\n                  var lon = '-1.9110';\n                  console.log(\"longitude Set Manually\");\n              }\n              else {\n                  var lon = position.coords.longitude;   \n                  console.log(\"longitude Set Automatically\");\n              };\n              locationcheck.handle_geolocation_query_successalt(position.coords.latitude,position.coords.longitude);\n              console.log(\"watchlocation Position Passed\");  \n     },\n<\/code><\/pre>\n<p>Every time I try and access position.coords.latitude or position.coords.longitude console says its<\/p>\n<blockquote>\n<p>&#8216;Uncaught Type Error: Can not read property &#8216;latitude&#8217; of undefined&#8217; &amp; &#8216;Uncaught Type Error: Can not read property &#8216;longitude&#8217; of undefined<\/p>\n<\/blockquote>\n<p>The end result of what I am trying to do here is grab the current location through the HTLM5 standard, if that does not work substitute the lat lon global variables.<\/p>\n<p>I suspect its probably down to my methods here as I am still learning the best way to do things as I have been able to access position.coords.latitude,position.coords.longitude as part of an alert box before now.<\/p>\n<p>TIA<\/p>\n<p>Terran<\/p>\n<p>EDIT J\u00f6rn Berkefelds comment that I had var postion = &#8220;&#8221;; else where was correct &#8211; I removed it and it resolved the problem.<\/p>\n<p>T<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:18:51. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>This is part of a function I have written watchlocation: function() { console.log(&#8220;watchlocation Started&#8221;); if (watchProcess == null) { watchProcess = navigator.geolocation.watchPosition(locationcheck.handle_geolocation_query_success, locationcheck.handle_errors, {enableHighAccuracy:true}); } if(position.coords.latitude == null) { var Lat = &#8216;52.5960&#8217;; console.log(&#8220;latitude Set Manually&#8221;); } else { var Lat = position.coords.latitude; console.log(&#8220;latitude Set Automatically&#8221;); }; if(position.coords.longitude == null) { var lon = &#8216;-1.9110&#8217;; [&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-526","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/526","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=526"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/526\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}