How To Detect Geolocation of Your Shopify Store’s Visitors
Detecting the geolocation (latitude and longitude) of your website’s users is useful for a variety of reasons. You might, want to help customer find stores near them.
Actually, the modern browsers was supported HTML Geolocation API. The HTML Geolocation API is used to get the geographical position of a user.
The example below returns the latitude and longitude of the user’s position:
1 2 3 4 5 6 7 8 9 10 11 12 | function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(setPosition); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function setPosition(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; alert('Latitude: '+latitude+' - Longitude:'+longitude); } |
Since this can compromise privacy, the position is not available unless the user approves it. So when you try to retrieve the location using this API, a prompt is shown to the user, asking them if they’d like to share their location with your site.
Actually, you can combine with Google Maps to build another features to your Shopify store.