2016-05-17 8 views
0

ブラウザに機能があるかどうかを確認するスクリプトを作成しました。次のスクリプトはエラーを生成します(navigator.geoloction)を使用したブラウザの機能の検出エラー

<!DOCTYPE HTML> 

<html> 
    <head> 
      <title id="title"> code Issues </title> 
    </head> 

    <body>  
      //=================== testing the feature detection method by using geolocation =======================// 
      function geosuccess(position) 
      { 
       var cords = position.cords; 
       var latitude = position.latitude; 
       var longitude = postion.longitude; 

       var message = "You're at " + latitude + ", " + longitude 

        alert(message); 
      } 

      function geoError(errorObj) 
      { 
       alert(errorObj.message); 
      } 

      if(typeof navigator.geolocation != "undefined") 
      { 
       console.log("inside geolocation"); 
       navigator.geolocation.getCurrentPosition(geoSuccess, geoError); 
      } 
      else 
      { 
       alert("thos page uses Geolocation and your browser doesn't support it"); 
      } 


      //=================== End of testing the feature detection method by using geolocation =======================// 


      </script> 


    <h1>List Publishers Ltd.</h1> 
    <div class="book"> 
     <h2>Sprout.</h2> 
     <p>A book by J. Daniel Bedford</p> 
     <a href="#">Read now.</a> 
    </div>  
    </body> 

</html> 

私はこれを実行すると、私はgeosuccessundefinedするエラーが発生します。

私はスクリプトをデバッグしようとしましたが、私はそれが機能geoSuccess(position)を検出できないことがわかります。

私はオブジェクト指向のコンセプトが欠けていないと思いますが、エラーはおそらくブラウザーに関連するものです。

答えて

1

まず、あなたのコードには開封<script>タグがありませんが、これは単なる間違いだと思います。

第2に、コードでは関数がgeosuccessと定義されていますが、geoSuccessgetCurrentPositionに渡します。あなたのコードで一致するケースを確認してください。

+0

あなたはまったく正しいと私は、私はその盲目であるとは思わない、たくさんの:) –

関連する問題