English 中文(简体)
传真 5 电话:Gap
原标题:HTML 5 geolocation using phoneGap
  • 时间:2011-09-30 23:16:34
  •  标签:
  • cordova

我制作了一个文字,将使用地勤图书馆显示用户的所在地,并对所有工作进行罚款。 我已经用电话交换了这一超文本5的文字,并且能够看到,在Cens->Location Services My App is set to On. 因此,我每次都假定,我管理我的申请不会及时。 是否希望利用你目前的位置?

我不想让人们点击,每次他们开着我的评估。 是否有理由说明该评估是否没有利用服务区和居民区的设置? 下面是简单的文字:

<!DOCTYPE html>
<html>
    <head>
        <meta name="apple-mobile-web-app-capable" content="yes" />

        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

        <link rel="apple-touch-icon-precomposed" href="custom_icon_precomposed.png"/>
        <link rel="apple-touch-startup-image" href="apple-touch-icon-precomposed.png">
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
            <script>

                jQuery(window).ready(function(){
                                     jQuery("#btnInit").click(initiate_watchlocation);
                                     jQuery("#btnStop").click(stop_watchlocation);
                                     });

                var watchProcess = null;

                function initiate_watchlocation() {  
                    if (watchProcess == null) {  
                        watchProcess = navigator.geolocation.watchPosition(handle_geolocation_query, handle_errors, {enableHighAccuracy:true});  
                    }  
                }  

                function stop_watchlocation() {  
                    if (watchProcess != null)  
                    {  
                        navigator.geolocation.clearWatch(watchProcess);  
                        watchProcess = null;  
                    }  
                }  

                function handle_errors(error)
                {
                    switch(error.code)
                    {
                        case error.PERMISSION_DENIED: alert("user did not share geolocation data");
                        break;

                        case error.POSITION_UNAVAILABLE: alert("could not detect current position");
                        break;

                        case error.TIMEOUT: alert("retrieving position timedout");
                        break;

                        default: alert("unknown error");
                        break;
                    }
                }

                function handle_geolocation_query(position) {  
                    var text = "Latitude: "  + position.coords.latitude  + "<br/>" +  
                    "Longitude: " + position.coords.longitude + "<br/>" +  
                    "Accuracy: "  + position.coords.accuracy  + "m<br/>" +  
                    "Time: " + new Date(position.timestamp);  
                    jQuery("#info").html(text);  

                    var image_url = "http://maps.google.com/maps/api/staticmap?sensor=false&center=" + position.coords.latitude +  ,  + position.coords.longitude +  
                    "&zoom=14&size=300x400&markers=color:blue|label:S|" + position.coords.latitude +  ,  + position.coords.longitude;  

                    jQuery("#map").remove();  
                    jQuery(document.body).append(  
                                                 jQuery(document.createElement("img")).attr("src", image_url).attr( id , map )  
                                                 );  
                }  
                </script>
            </head>
    <body>
        <div>
            <button id="btnInit" >Monitor my location</button>

            <button id="btnStop" >Stop monitoring</button>
        </div>
        <div id="info"></div>
    </body>
</html>
最佳回答

我看一看所有情况,发现你必须等到该装置准备就绪,然后打电话给你的窗户。 准备利用土著职能。 虽然我这样说,但找到我所寻求的答案是不足的。

        // Wait for PhoneGap to load
        //
        document.addEventListener("deviceready", onDeviceReady, false);

        // PhoneGap is ready
        //
        function onDeviceReady() {
            jQuery(window).ready(function(){
                jQuery("#btnInit").click(initiate_watchlocation);
                jQuery("#btnStop").click(stop_watchlocation);
            });

        }
问题回答

暂无回答




相关问题
Javascript data store solution using PhoneGap

Does anyone have any experience of storing data in JavaScript across all mobile platforms using PhoneGap? My ideal solution would be to use something like SQLite, but unfortunately SQLite isn t ...

get image from iphone, using phonegap camera api

I m new to Xcode and iPhone apps. I want to select an image from iPhone (camera or library) and send to php via ajax. http://wiki.phonegap.com/iPhone:-Camera-API I m using the phonegap framework, ...

Getting Search Keyboard on iPhone using PhoneGap

I have created a search field on a mobile app i am creating via PhoneGap. I ve tried using with no luck. I also know that i could get around the visual aspect of the input field via CSS & ...

How can I detect a shake gesture in PhoneGap 0.8?

I m using PhoneGap 0.8 and I d like to detect a basic shake gesture. I ve found two relevant snippets: http://groups.google.com/group/phonegap/browse_thread/thread/25178468b8eb9e9f http://phonegap....

How do I fix PhoneGap build errors?

I am trying to build a PhoneGap-based iPhone application, but I keep getting the following two errors: ./build-phonegap.sh: line 6: ./configure: No such file or directory cp: lib/iphone/phonegap-min....

热门标签