{"id":1102,"date":"2015-12-09T18:05:03","date_gmt":"2015-12-09T18:05:03","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=1102"},"modified":"2022-11-13T06:27:28","modified_gmt":"2022-11-13T06:27:28","slug":"get-visitor-location-using-html5-geolocation-api-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/","title":{"rendered":"Get Visitor Location using HTML5 Geolocation API and PHP"},"content":{"rendered":"<p>Many web application tracks the geographical information of the visitor or user. Tracking the visitor&#8217;s location can be done by many ways. There are many third-party API services available to get the <b>user location by IP address<\/b>. These geolocation service providers charge for using their API. This tutorial shows how you can get the user location at free of cost using HTML Geolocation API.<\/p>\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-from-browser-php-geolocation-api-coddexworld.png\" alt=\"get-user-location-from-browser-php-geolocation-api-coddexworld\" width=\"575\" height=\"191\" class=\"alignnone size-full wp-image-2904\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-from-browser-php-geolocation-api-coddexworld.png 575w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-from-browser-php-geolocation-api-coddexworld-300x100.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-from-browser-php-geolocation-api-coddexworld-200x66.png 200w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-from-browser-php-geolocation-api-coddexworld-346x115.png 346w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/div>\n<p>The <b>HTML5 Geolocation API<\/b> helps to get geographical location of a user. You can locate the visitor&#8217;s position using HTML Geolocation API. But HTML Geolocation will provide the location if the user approves it. Otherwise, the user position will not be available. Once you get the visitor latitude and longitude by HTML5 Geolocation API, you can get the website visitor\u2019s country, state, city, location, and zip code by Google Maps API.<\/p>\n<p>In this tutorial, we will show you how to implement visitor location tracking functionality in the website using <b>HTML Geolocation API and PHP<\/b>. The following functionality will be implemented to <b>get user location from browser<\/b> using Geolocation API and PHP.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Get the latitude and longitude of the current user using HTML Geolocation API.<\/li>\n<li>Get the location by latitude &#038; longitude using Google Maps Geocoding API and PHP.<\/li>\n<\/ul>\n<p>We will use two files (<code>index.html<\/code> and <code>getLocation.php<\/code>) to get the geographical location of the user.<\/p>\n<h2>index.html<\/h2>\n<p>At first, we will retrieve the visitor\u2019s latitude and longitude using HTML5 Geolocation API. After that, we will send this latitude and longitude to the getLocation.php file using jQuery Ajax to get the visitor\u2019s address. Once the response is received from the <code>getLocation.php<\/code> file, the visitor\u2019s location will be displayed in the specified area (<code>#location<\/code>).<\/p>\n<p><b>JavaScript Code:<\/b><br \/>\nThe jQuery Ajax is used to post the latitude and longitude to PHP file. So, include the jQuery library first.<\/p>\n<pre>&lt;<span style=\"color:#bf4f24\">script<\/span> <span style=\"color:#bf4f24\">src<\/span>=<span style=\"color:#0b6125\">\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.2.1\/jquery.min.js\"<\/span>>&lt;\/<span style=\"color:#bf4f24\">script<\/span>>\r\n<\/pre>\n<p>The <code>getCurrentPosition()<\/code> method is used to get the visitor&#8217;s position and <code>showLocation()<\/code> method is used to getting the visitor&#8217;s address from the getLocation.php file using Ajax.<\/p>\n<pre>&lt;<span style=\"color:#bf4f24\">script<\/span>>\r\n<span style=\"color:#691c97\">$<\/span>(<span style=\"color:#691c97\">document<\/span>)<span style=\"color:#693a17\">.ready<\/span>(<span style=\"color:#a71d5d;font-style:italic\">function<\/span>(){\r\n    <span style=\"color:#794938\">if<\/span>(<span style=\"color:#691c97\">navigator<\/span>.geolocation){\r\n        <span style=\"color:#691c97\">navigator<\/span>.geolocation.getCurrentPosition(showLocation);\r\n    }<span style=\"color:#794938\">else<\/span>{ \r\n        <span style=\"color:#691c97\">$<\/span>('<span style=\"color:#bf4f24\">#location<\/span>')<span style=\"color:#693a17\">.html<\/span>(<span style=\"color:#0b6125\">'Geolocation is not supported by this browser.'<\/span>);\r\n    }\r\n});\r\n\r\n<span style=\"color:#a71d5d;font-style:italic\">function<\/span> <span style=\"color:#bf4f24\">showLocation<\/span>(position){\r\n    <span style=\"color:#a71d5d;font-style:italic\">var<\/span> latitude <span style=\"color:#794938\">=<\/span> position.<span style=\"color:#b4371f\">coords<\/span>.latitude;\r\n    <span style=\"color:#a71d5d;font-style:italic\">var<\/span> longitude <span style=\"color:#794938\">=<\/span> position.<span style=\"color:#b4371f\">coords<\/span>.longitude;\r\n    <span style=\"color:#794938\">$<\/span><span style=\"color:#693a17\">.ajax<\/span>({\r\n        type:<span style=\"color:#0b6125\">'POST'<\/span>,\r\n        url:<span style=\"color:#0b6125\">'getLocation.php'<\/span>,\r\n        data:<span style=\"color:#0b6125\">'latitude='<\/span><span style=\"color:#794938\">+<\/span>latitude<span style=\"color:#794938\">+<\/span><span style=\"color:#0b6125\">'&amp;longitude='<\/span><span style=\"color:#794938\">+<\/span>longitude,\r\n        <span style=\"color:#bf4f24\">success<\/span>:<span style=\"color:#a71d5d;font-style:italic\">function<\/span>(msg){\r\n            <span style=\"color:#794938\">if<\/span>(msg){\r\n               <span style=\"color:#691c97\">$<\/span>(\"<span style=\"color:#bf4f24\">#location<\/span>\")<span style=\"color:#693a17\">.html<\/span>(msg);\r\n            }<span style=\"color:#794938\">else<\/span>{\r\n                <span style=\"color:#691c97\">$<\/span>(\"<span style=\"color:#bf4f24\">#location<\/span>\")<span style=\"color:#693a17\">.html<\/span>(<span style=\"color:#0b6125\">'Not Available'<\/span>);\r\n            }\r\n        }\r\n    });\r\n}\r\n&lt;\/<span style=\"color:#bf4f24\">script<\/span>>\r\n<\/pre>\n<p><b>HTML Code:<\/b><br \/>\nAfter getting the visitor position, the address will be shown on the web page (<code>#location<\/code> span).<\/p>\n<pre>&lt;<span style=\"color:#bf4f24\">p<\/span>>Your Location: &lt;<span style=\"color:#bf4f24\">span<\/span> <span style=\"color:#bf4f24\">id<\/span><span style=\"color:#794938\">=<\/span><span style=\"color:#0b6125\">\"location\"<\/span>>&lt;\/<span style=\"color:#bf4f24\">span<\/span>>&lt;\/<span style=\"color:#bf4f24\">p<\/span>>\r\n<\/pre>\n<h2>getLocation.php<\/h2>\n<p>In this file, the geographic coordinates (latitude and longitude) is converted into a human-readable address using Google Maps Geocoding API and PHP. Based on the latitude and longitude, the formatted_address is fetched and the response is sent to the Ajax success function.<\/p>\n<pre><span style=\"color: #0000BB\">&lt;?php<br \/><\/span><span style=\"color: #FF8000\">\/\/if&nbsp;latitude&nbsp;and&nbsp;longitude&nbsp;are&nbsp;submitted<br \/><\/span><span style=\"color: #007700\">if(!empty(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'latitude'<\/span><span style=\"color: #007700\">])&nbsp;&amp;&amp;&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'longitude'<\/span><span style=\"color: #007700\">])){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/send&nbsp;request&nbsp;and&nbsp;receive&nbsp;json&nbsp;data&nbsp;by&nbsp;latitude&nbsp;and&nbsp;longitude<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$url&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'http:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?latlng='<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">trim<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'latitude'<\/span><span style=\"color: #007700\">]).<\/span><span style=\"color: #DD0000\">','<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">trim<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'longitude'<\/span><span style=\"color: #007700\">]).<\/span><span style=\"color: #DD0000\">'&amp;sensor=false'<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$json&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;@<\/span><span style=\"color: #0000BB\">file_get_contents<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$url<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">json_decode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$json<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">status<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/if&nbsp;request&nbsp;status&nbsp;is&nbsp;successful<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(<\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">==&nbsp;<\/span><span style=\"color: #DD0000\">\"OK\"<\/span><span style=\"color: #007700\">){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/get&nbsp;address&nbsp;from&nbsp;json&nbsp;data<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$location&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">results<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">]-&gt;<\/span><span style=\"color: #0000BB\">formatted_address<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}else{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$location&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/return&nbsp;address&nbsp;to&nbsp;ajax&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$location<\/span><span style=\"color: #007700\">;<br \/>}<br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/get-geolocation-country-latitude-longitude-from-ip-address-using-php\/\">Get Geolocation (Country, Latitude, and Longitude) from IP Address using PHP<\/a><\/span><\/p>\n<h2>Browsers Support<\/h2>\n<p>All major browser supports HTML5 Geolocation. But as of Google Chrome 50, the HTML Geolocation API is no longer supported over HTTP. The <b>getcurrentposition()<\/b> and <b>watchposition()<\/b> are deprecated on insecure origins in Chrome 50. The Geolocation API will only work on secure origins such as HTTPS. You can check the more details about this issue from <a href=\"https:\/\/www.codexworld.com\/how-to\/html5-geolocation-not-working-chrome\/\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many web application tracks the geographical information of the visitor or user. Tracking the visitor&#8217;s location can be done by many ways. There are many third-party API services available to get the user location by <\/p>\n","protected":false},"author":1,"featured_media":2901,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[103,35,102,14],"class_list":["post-1102","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-geolocationapi","tag-google-maps-api","tag-html5","tag-php","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Get Visitor Location using HTML5 Geolocation API and PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Get user location from browser using PHP \u2013 Learn how to get website visitor\u2019s current location using HTML5 Geolocation API, Google Maps API, and PHP\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Visitor Location using HTML5 Geolocation API and PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Get user location from browser using PHP \u2013 Learn how to get website visitor\u2019s current location using HTML5 Geolocation API, Google Maps API, and PHP\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2015-12-09T18:05:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-13T06:27:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-html5-geolocation-api-php-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1337\" \/>\n\t<meta property=\"og:image:height\" content=\"752\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Get Visitor Location using HTML5 Geolocation API and PHP\",\"datePublished\":\"2015-12-09T18:05:03+00:00\",\"dateModified\":\"2022-11-13T06:27:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/\"},\"wordCount\":465,\"commentCount\":24,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/12\\\/get-user-location-html5-geolocation-api-php-codexworld.png\",\"keywords\":[\"GeolocationAPI\",\"Google Maps API\",\"HTML5\",\"PHP\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/\",\"name\":\"Get Visitor Location using HTML5 Geolocation API and PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/12\\\/get-user-location-html5-geolocation-api-php-codexworld.png\",\"datePublished\":\"2015-12-09T18:05:03+00:00\",\"dateModified\":\"2022-11-13T06:27:28+00:00\",\"description\":\"Get user location from browser using PHP \u2013 Learn how to get website visitor\u2019s current location using HTML5 Geolocation API, Google Maps API, and PHP\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/12\\\/get-user-location-html5-geolocation-api-php-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/12\\\/get-user-location-html5-geolocation-api-php-codexworld.png\",\"width\":1337,\"height\":752,\"caption\":\"get-user-location-html5-geolocation-api-php-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/get-visitor-location-using-html5-geolocation-api-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Visitor Location using HTML5 Geolocation API and PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Visitor Location using HTML5 Geolocation API and PHP - CodexWorld","description":"Get user location from browser using PHP \u2013 Learn how to get website visitor\u2019s current location using HTML5 Geolocation API, Google Maps API, and PHP","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/","og_locale":"en_US","og_type":"article","og_title":"Get Visitor Location using HTML5 Geolocation API and PHP - CodexWorld","og_description":"Get user location from browser using PHP \u2013 Learn how to get website visitor\u2019s current location using HTML5 Geolocation API, Google Maps API, and PHP","og_url":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2015-12-09T18:05:03+00:00","article_modified_time":"2022-11-13T06:27:28+00:00","og_image":[{"width":1337,"height":752,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-html5-geolocation-api-php-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Get Visitor Location using HTML5 Geolocation API and PHP","datePublished":"2015-12-09T18:05:03+00:00","dateModified":"2022-11-13T06:27:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/"},"wordCount":465,"commentCount":24,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-html5-geolocation-api-php-codexworld.png","keywords":["GeolocationAPI","Google Maps API","HTML5","PHP"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/","url":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/","name":"Get Visitor Location using HTML5 Geolocation API and PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-html5-geolocation-api-php-codexworld.png","datePublished":"2015-12-09T18:05:03+00:00","dateModified":"2022-11-13T06:27:28+00:00","description":"Get user location from browser using PHP \u2013 Learn how to get website visitor\u2019s current location using HTML5 Geolocation API, Google Maps API, and PHP","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-html5-geolocation-api-php-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-html5-geolocation-api-php-codexworld.png","width":1337,"height":752,"caption":"get-user-location-html5-geolocation-api-php-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/get-visitor-location-using-html5-geolocation-api-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Get Visitor Location using HTML5 Geolocation API and PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/12\/get-user-location-html5-geolocation-api-php-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-hM","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=1102"}],"version-history":[{"count":7,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1102\/revisions"}],"predecessor-version":[{"id":4650,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1102\/revisions\/4650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/2901"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=1102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=1102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=1102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}