【问题标题】:How to find Geolocation (longitude and latitude)in jquery mobile +phonegap如何在jquery mobile +phonegap中查找地理位置(经度和纬度)
【发布时间】:2013-07-05 12:39:07
【问题描述】:

你能告诉我如何使用phonegap在jquery mobile中找到地理位置(经度和纬度)。然后我需要在地图上显示位置。

【问题讨论】:

    标签: android jquery-mobile cordova


    【解决方案1】:

    我假设您已推荐 Phonegap's Getting Started Guide 创建基本项目。

    这是获取纬度和经度的脚本

    /*
     * This file contains script to get lattitude and longitude
     * 
     */
    var lat = 0;
    var lng = 0;
    //A button click will call this function
    function getLocation() {
        navigator.geolocation.getCurrentPosition(onSuccess, onError, { enableHighAccuracy: true });
    }
    
    // onSuccess Geolocation
    //
    function onSuccess(position) {
        //Lat long will be fetched and stored in session variables
        //These variables will be used while storing data in local database 
        lat = position.coords.latitude;
        lng = position.coords.longitude;
        alert('Lattitude: ' + lat + ' Longitude: ' + long);
        sessionStorage.setItem('lattitude', lat);
        sessionStorage.setItem('longitude', lng);
    }
    // onError Callback receives a PositionError object
    //
    function onError(error) {
        alert('code: ' + error.code + '\n' +
              'message: ' + error.message + '\n');
    }
    

    您必须在 ma​​nifest 文件中添加必要的权限。

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    

    调用getLocation() function onclick 按钮或任何您希望获取地理位置的事件。

    更多详情请咨询Phonegap Geolocation Documentation

    要显示谷歌地图,请参考Google MAP API

    希望对您有所帮助。

    【讨论】:

    • 感谢获得好的演示。你能告诉我如何显示这个经纬度图吗..?
    • 很高兴有帮助。我在上面的答案中提到了一个显示地图的链接。要显示谷歌地图,请参考Google MAP API
    猜你喜欢
    • 2018-07-26
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多