Reputation: 540
Im trying to implement the geolocation services to get the latitude and longitude values, but in Safari it just doesnt work. And then in firefox it works, but it doesnt know how to handle errors. I have no idea why.
Below is my code.
<!DOCTYPE html>
<html lang="en">
<head>
<title>GPS</title>
</head>
<body>
<strong>Output:</strong>
<input type="text" id = "mapLink" value="">
<script type = "text/javascript">
navigator.geolocation.getCurrentPosition(showMap, handle_error);
function showMap(position){
var lat = position.coords.latitude;
var long = position.coords.longitude;
var linkUrl = lat + "," + long;
var mapLink = document.getElementById("mapLink");
mapLink.value = linkUrl;
}
function handle_error(err) {
alert('error');
}
</script>
</body>
</html>
Upvotes: 1
Views: 12664
Reputation: 1
It has to go through HTTPS. The release notes say "WebGeolocation now requires a secure (HTTPS) website to work on both iOS and macOS to prevent malicious use of location data." under the "Safari" heading. https://forums.developer.apple.com/thread/54276
Upvotes: 0
Reputation: 3149
Safari does support Geolocation. But to make your life easier, check out http://code.google.com/p/geo-location-javascript/.
Upvotes: 1