{"id":4313,"date":"2025-04-24T19:27:53","date_gmt":"2025-04-24T18:27:53","guid":{"rendered":"https:\/\/ibex.tech\/javascript\/?p=4313"},"modified":"2025-04-24T19:27:53","modified_gmt":"2025-04-24T18:27:53","slug":"get-users-latitude-and-longitude","status":"publish","type":"post","link":"https:\/\/ibex.tech\/javascript\/geolocation\/get-users-latitude-and-longitude","title":{"rendered":"Get users latitude and longitude"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;form class=\"HomePagePostcodeForm\" id=\"HomePagePostcodeForm\" method=\"POST\" >\n    &lt;input type=\"hidden\" name=\"form_submit_id\" value=\"home_page_set_postcode\" \/>\n\n    &lt;input type=\"hidden\" name=\"geolocation_longitude\" id=\"geolocation_longitude\" value=\"0\" \/>\n    &lt;input type=\"hidden\" name=\"geolocation_latitude\" id=\"geolocation_latitude\" value=\"0\" \/>\n\n    &lt;input type=\"text\" name=\"set_postcode\" placeholder=\"e.g. BS1 5UH\" value=\"\" \/>\n\n    &lt;input type=\"submit\"  value=\"Search\" \/>\n\n    &lt;input type=\"Button\" onclick=\"GetGeolocation(); return false;\" value=\"Use my location\" \/>\n  &lt;\/form>\n\n\n  &lt;script>\n    function GetGeolocation()\n    {\n      if (!navigator.geolocation)\n      {\n        alert('Geolocation is not supported by your browser.');\n        return;\n      }\n\n      navigator.geolocation.getCurrentPosition(getCurrentPosition_Success, getCurrentPosition_Error);\n      \n      function getCurrentPosition_Success (position)\n      {\n        \/\/Success\n        document.getElementById('geolocation_longitude').value = position.coords.longitude;\n        document.getElementById('geolocation_latitude').value = position.coords.latitude;\n\n        \/\/Submit the form\n        document.getElementById('HomePagePostcodeForm').submit();\n      }\n      \n      function getCurrentPosition_Error (error)\n      {\n        alert('Unable to retrieve your location. Reason: ' + error.message);\n      }\n    }\n  &lt;\/script><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[339],"tags":[],"class_list":["post-4313","post","type-post","status-publish","format-standard","hentry","category-geolocation"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/comments?post=4313"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4313\/revisions"}],"predecessor-version":[{"id":4314,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4313\/revisions\/4314"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/media?parent=4313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/categories?post=4313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/tags?post=4313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}