I am using HTML5 geolocation which is not working on safari browser,but its working fine on Chrome,IE,Mozila,here is my current javascript code
<script>
$(function () {
$("#btnLocateMe").click(function () {
if ($("#txtLat").val() == "" || $("#txtLng").val() == "")
{
show_user_location();
}
else
{
$("#btnRedirect").trigger("click");
}
});
});
function show_user_location() {
navigator.geolocation.getCurrentPosition(display_user_location, error_response);
}
function display_user_location(user_position) {
var lat = user_position.coords.latitude;
var lon = user_position.coords.longitude;
$("#txtLat").val(lat);
$("#txtLng").val(lon);
$("#btnRedirect").trigger("click");
}
function error_response() {
alert("Location is required to find restaurants near by you.");
}
</script>
How do I make it work on safari also?
You didn't mention Safari browser version in which code isn't working, and your website link to verify issue, you can try this
Open System Preferences / Security and select the General tab.
Click the gold padlock icon bottom left in the pane to make any necessary changes. You will be prompted for your admin password.
If necessary, make sure: Disable Location Services is not selected. Click: Reset Warnings.Relaunch Safari. See if that made a difference.
also, please check these links which may help
According to https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition geolocation is supported in Safari 5.0 and above
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly