{"id":1100,"date":"2022-08-30T15:12:23","date_gmt":"2022-08-30T15:12:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/write-a-location-and-get-the-geocords-not-working-properly-js-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:12:23","modified_gmt":"2022-08-30T15:12:23","slug":"write-a-location-and-get-the-geocords-not-working-properly-js-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/write-a-location-and-get-the-geocords-not-working-properly-js-collection-of-common-programming-errors\/","title":{"rendered":"Write a location and get the geocords, not working properly? JS-Collection of common programming errors"},"content":{"rendered":"<p>Link removed<\/p>\n<p>This is my site. Im working on so you can enter a location on the search input field, and then see theres xx km from a restaurant.<\/p>\n<p>Now i got almost everything working. If you see the source code you can see how it works. It showAddress(what you searched). And then show addresses makes it into lat\/lng cords, and pass it to computeRestaurants() which computes the distances between the location you entered and the restaurants.<\/p>\n<p>Somehow, when I run:<\/p>\n<pre><code>computeRestaurants(new google.maps.LatLng(55.662133, 12.508028)); \n<\/code><\/pre>\n<p>outside the functions, it works and gives correct values.<\/p>\n<p>But when i do:<\/p>\n<pre><code>showAddress('Valby'); \/\/ (like in the source code)\n<\/code><\/pre>\n<p>You can see that it returns NaN. And inside showAddress() it executes the same command as the one i wrote above computeRestaurants( the point )<\/p>\n<p>So why will it not work properly?<\/p>\n<p><code>point<\/code> in showAddress is: <code>(55.662133, 12.508028)<\/code> so it is already converted to LatLng cords and therefore no need to <code>new google.maps.latlng(...<\/code><\/p>\n<p>My only bet right now is the brackets () ??<\/p>\n<ol>\n<li>\n<p>replace your showAddress by this:<\/p>\n<pre><code>var geocoder;\nfunction showAddress(address)\n{\n  if (typeof(geocoder) == 'undefined') geocoder = new google.maps.Geocoder();\n\n  geocoder.geocode( { 'address': address}, function(results, status) {\n    if (status == google.maps.GeocoderStatus.OK) {\n      computeRestaurants(results[0].geometry.location);\n    } else {\n      alert(\"Geocode was not successful for the following reason: \" + status);\n    }\n  });\n}\n<\/code><\/pre>\n<p>You are using mixup of v2 and v3 apis, and that is the problem.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:24:09. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Link removed This is my site. Im working on so you can enter a location on the search input field, and then see theres xx km from a restaurant. Now i got almost everything working. If you see the source code you can see how it works. It showAddress(what you searched). And then show addresses [&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-1100","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1100","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=1100"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1100\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}