Javascript – Beispiele für die Positionierung von HTML-Code
为情所困
为情所困 2017-05-19 10:40:51
0
2
394
 <p id="location"></p>
    <script type="text/javascript">
        //检测浏览器是否支持API
        window.onload=getLocation;
        function getLocation(){
            var locationElement=document.getElementById("location");
            if(navigator.geoLocation){
                navigator.geoLocation.getCurrentPosition(successCallBack,errorCallback,{enableHighAccuracy:true,timeout:3000,maximumAge:60000});
            }
            else{
                locationElement.innerHTML="GeoLocation is not supported in your browser.";
            }
        }
             //处理获取的position数据
            function successCallBack(position){
                var latitude=position.coords.latitude;   //获取纬度值
                var longitude=position.coords.longitude;//获取经度值
                locationElement.innerHTML="latitude:"+latitude+",longitude:"+longitude;
            }
            //处理错位信息
            function errorCallback(error){
                 switch(error.code){
                     case 1:
                        console.log("用户选择拒绝浏览器获得其位置信息");
                     break;
                     case 2:
                        console.log("尝试获取用户位置信息,但失败了");
                     break;
                     case 3:
                        console.log("莫名其妙的错误");
                     break;
                 }
            }
    </script>
    参考书籍写了一段关于html定位的代码,换了好几个浏览器,都呈现:
    GeoLocation is not supported in your browser.现在不晓得问题出在哪了,还望大神指教?谢谢
为情所困
为情所困

Antworte allen(2)
世界只因有你

geolocation

l小写的...

洪涛

单词写错啦geolocation
应该是

navigator.geolocation

geolocation不是两个单词组合的,所以不用驼峰

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage