问题
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>
回答1:
Safari does support Geolocation. But to make your life easier, check out http://code.google.com/p/geo-location-javascript/.
回答2:
You can try, but safari support geo only in new versions, you can try in Google Chrome or Firefox
<script>
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
alert('Browset support geo')
}
</script>
I implement parctialy geolocation example in this site www.baireswifi.com.ar you can try in your safari. If not working is for use older browser.
回答3:
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
来源:https://stackoverflow.com/questions/7350033/geolocation-not-working-in-safari