Home  >  Article  >  Web Front-end  >  Detailed explanation of phonegap obtaining location information

Detailed explanation of phonegap obtaining location information

php中世界最好的语言
php中世界最好的语言Original
2018-03-26 15:30:161460browse

This time I will bring you a detailed explanation of phonegap obtaining location information. What are the precautions for phonegap to obtain location information. The following is a practical case, let’s take a look.

The examples are as follows:

<!DOCTYPE html> 
<html> 
  
    <head> 
        <meta charset="UTF-8"> 
        <title>Compass Example</title> 
  
        <script type="text/javascript" charset="UTF-8" src="cordova.js"></script> 
        <script type="text/javascript" charset="UTF-8"> 
            document.addEventListener("deviceready", onDeviceReady, false); 
  
            function onDeviceReady() { 
                getPosition(); 
            } 
              
            //获取当前位置信息 
            function getPosition() { 
                navigator.geolocation.getCurrentPosition(onSuccess,onError); 
            } 
  
  
            //错误的回调  
            function onError(error) { 
                alert('code:'+error.code+'\n'+'message:'+error.message+'\n'); 
            } 
  
            //成功的回调  
            function onSuccess(position) { 
                alert('Latitude:'+position.coords.latitude+'\n'+ 
                'Longitude:'+position.coords.longitude+'\n'+ 
                'Altitude:'+position.coords.altitude+'\n'+ 
                'Accuracy:'+position.coords.accuracy+'\n'+ 
                'Altitude Accuracy:'+position.coords.altitudeAccuracy+'\n'+ 
                'Heading:'+position.coords.heading+'\n'+ 
                'Speed:'+position.coords.speed+'\n'+ 
                'Timestamp:'+new Date(position.timeStamp)+'\n'); 
            } 
        </script> 
    </head> 
  
    <body> 
        <button onclick="getPosition();">Start Watching</button> 
    </body> 
  
</html>

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website !

Recommended reading:

Detailed explanation of phonegap operation database

##How to change the code of the current url without refreshing

The above is the detailed content of Detailed explanation of phonegap obtaining location information. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn