admin管理员组文章数量:1391969
I'm trying to geolocate with the navigator.geolocation.getCurrentPosition() function, but I can't seem to get it working on firefox. More specifically, I made a very simple HTML file:
<!DOCTYPE HTML>
<html>
<head>
<script src=".exp&sensor=false&libraries=places"></script>
<script type="text/javascript" src=".8.3/jquery.min.js"></script>
<script type="text/javascript" src="js/mapHandler.js"></script>
</head>
<body>
</body>
</html>
As you can see, it's the bare minimum of an HTML file. The javascript just does the following:
function displayLocation (position)
{
alert("displayLocation");
}
function displayError(positionErr)
{
alert("error");
}
function initialize()
{
if (!(navigator.geolocation == 'undefined'))
{
navigator.geolocation.getCurrentPosition(displayLocation, displayError,{timeout:10000});
}
else
{
alert('Geolocation unsupported');
}
}
$(document).ready(function(){initialize() });
Once again, it's a very very simple example which just asks for the position and makes a couple of alert. The strange thing is that when I launch the script I can't seem to get any answer. Does anyone know why? Thanks in advance :)
I'm trying to geolocate with the navigator.geolocation.getCurrentPosition() function, but I can't seem to get it working on firefox. More specifically, I made a very simple HTML file:
<!DOCTYPE HTML>
<html>
<head>
<script src="https://maps.googleapis./maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare./ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="js/mapHandler.js"></script>
</head>
<body>
</body>
</html>
As you can see, it's the bare minimum of an HTML file. The javascript just does the following:
function displayLocation (position)
{
alert("displayLocation");
}
function displayError(positionErr)
{
alert("error");
}
function initialize()
{
if (!(navigator.geolocation == 'undefined'))
{
navigator.geolocation.getCurrentPosition(displayLocation, displayError,{timeout:10000});
}
else
{
alert('Geolocation unsupported');
}
}
$(document).ready(function(){initialize() });
Once again, it's a very very simple example which just asks for the position and makes a couple of alert. The strange thing is that when I launch the script I can't seem to get any answer. Does anyone know why? Thanks in advance :)
Share Improve this question asked Feb 9, 2014 at 16:26 Stefano KiraStefano Kira 1752 gold badges3 silver badges16 bronze badges 3- Which version of Firefox are you using? – Siva Charan Commented Feb 9, 2014 at 16:28
- This example is working also with FF. Maybe you have no enabled location sharing. – Anto Jurković Commented Feb 9, 2014 at 19:24
- Still happening to me on 2020, with Firefox "Developer Edition" 76. What a shame. – tomyo Commented May 9, 2020 at 0:58
3 Answers
Reset to default 2Actually I tested it on Chrome 32(It worked fine) and Firefox 26 (No luck).
I tried enabling geolocation on Firefox but still doesn't work.
I have browsed couple sites on the google and finally What I understood is Firefox 26 & 27 has a bug in detecting the geolocation.
For testing the functionality, you can run this LIVE DEMO which is a plain javascript.
initialize();
function displayLocation(position) {
var cords = position.coords;
alert("displayLocation, lat='"+cords.latitude+"'; long='"+cords.longitude+"'");
}
function displayError(positionErr) {
alert("error");
}
function initialize() {
if (!(navigator.geolocation == 'undefined')) {
navigator.geolocation.getCurrentPosition(displayLocation, displayError, {
timeout: 10000
});
} else {
alert('Geolocation unsupported');
}
}
Seem's the note is important :
http://www.w3schools./html/html5_geolocation.asp
Browser Support
Internet Explorer 9+, Firefox, Chrome, Safari and Opera support Geolocation.
Note: Geolocation is much more accurate for devices with GPS, like iPhone.
Done the try it test : http://www.w3schools./html/tryit.asp?filename=tryhtml5_geolocation
-> On puter using Firefox 26.0 : Nothing happened. Even when sharing position (No GPS device connected).
-> On android smartphone using firefox 27.0 : Get Latitude & Longitude from GPS
It seems that there is a problem with geolocation on Mozilla Firefox 24+ based on
https://support.mozilla/en-US/questions/984520
Run Firefox with administrative privileges (especially on Windows).
本文标签: javascriptgetCurrentPosition() not working in firefoxStack Overflow
版权声明:本文标题:javascript - getCurrentPosition() not working in firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744734427a2622239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论