Jquery mobile Google Maps JS API v3未使用Phonegap iOS 3.5.0和jQuery Mobile进行地理定位

Jquery mobile Google Maps JS API v3未使用Phonegap iOS 3.5.0和jQuery Mobile进行地理定位,jquery-mobile,cordova,google-geolocation,Jquery Mobile,Cordova,Google Geolocation,设置 目前正在构建my phone gap iOS应用程序,除了将结果发送到数据库并返回附近位置外,还包括地理定位。因为我使用的是jQuery Mobile和Phonegap,所以我在一个浏览器上进行了完美的测试,地理定位成功了,返回的所有内容也都成功了。在iOS设备上,没有那么多。当发送设置的纬度和经度时,所有内容都成功返回,但是当使用google maps geolocation以及最终的用于geolocation的cordova插件时,两者都失败了,因为无法找到我的位置,即使它们是完全相同

设置

目前正在构建my phone gap iOS应用程序,除了将结果发送到数据库并返回附近位置外,还包括地理定位。因为我使用的是jQuery Mobile和Phonegap,所以我在一个浏览器上进行了完美的测试,地理定位成功了,返回的所有内容也都成功了。在iOS设备上,没有那么多。当发送设置的纬度和经度时,所有内容都成功返回,但是当使用google maps geolocation以及最终的用于geolocation的cordova插件时,两者都失败了,因为无法找到我的位置,即使它们是完全相同的代码,减去网站上的电话间隔初始值

代码

jQuery

HTML


还有更多需要了解的内容

我一直在阅读其他相关问题,但其他问题都没有解决。要么他们说使用插件,我没有用,要么我已经设置了
。此外,其他大多数问题都围绕着phone gap的3.0.0之前版本展开,而phone gap本身就是一个怪物。此外,地图将加载,但不会显示任何标记。在数据库上,正在更新位置的用户设置为(0,0)。最后,当在任何其他应用程序中使用地理位置时,我测试的iOS设备会成功找到我的位置。此外,我正在与浏览器工作的WiFi网络上进行测试,因此排除了由于网络或硬件原因而导致内部无法定位的任何情况

如果您想查看工作示例,请询问。

试试这个插件。
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
$(document).ready(function () {
    //Load Google Map & Geolocate
    $(document).on("pagecreate", "#game", function () {
        // keep as separate function call to allow for DOM to update after a tag
        loadGoogleMap();
    });

    function loadGoogleMap() {
            var defaultLatLng = new google.maps.LatLng(34.0983425, -118.3267434); //default location is Hollywood, CA

            if (navigator.geolocation) {
                function success(pos) {
                    //set fields for current user latitude and longitude
                    $("#lat_in").val(pos.coords.latitude);
                    $("#lon_in").val(pos.coords.longitude);

                    //location found
                    drawMap(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
                }

                function fail(error) {
                    //try cordova geolocation plugin
                    function onSuccess(position) {
                        alert("CDV position success");
                        //alert(position.coords.latitude);
                        //alert(position.coords.longitude);
                    }

                    function onError(error) {
                        alert("CDV position error");
                        //alert("code: " + error.code + "\n" + "message: " + error.message);
                    }

                    navigator.geolocation.getCurrentPosition(onSuccess, onError);

                    alert("CDV position fail. Google geolocate fail"); //WHERE THE ERROR IS THROWN. THIS IS ALWAYS THE OUTCOME

                    //drawMap(defaultLatLng); //Failed to find location. Show default location
                }

                //Geolocate. Cache location for 5 mins. Timeout after 6 seconds
                navigator.geolocation.getCurrentPosition(success, fail, {
                    maximumAge: 500000,
                    enableHighAccuracy: true,
                    timeout: 6000
                });
            } else {
                drawMap(defaultLatLng); //No geolocation support, show default map
            }

            function drawMap(latlng) {
                    //Collect Data to Send
                    var uname = $("#unm_in").val();
                    var lat = $("#lat_in").val();
                    var lon = $("#lon_in").val();

                    var myOptions = {
                        zoom: 16,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    };

                    var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);

                    //update latitude and longitude on DB for logged in user && get nearby users
                    $.post("PHP_ON_SERVER", {
                        uname: uname,
                        lat: lat,
                        lon: lon
                    }, function (data) {
                        $.each(data, function (key, value) {
                            //Define variables
                            var allUsrLoc = new google.maps.LatLng(value.lat, value.lon);
                            var contentString = value.uname;
                            var mkrImg = "inUsrIcon.png"; //icon for logged in user
                            var inUserName = value.fname + " " + value.lname;

                            //if info belongs to current user
                            if (contentString === uname) {
                                var marker = new google.maps.Marker({
                                    position: allUsrLoc,
                                    map: map,
                                    title: "Player",
                                    icon: mkrImg
                                });

                                //change header to name and points
                                $("#inUserInfo").text("Hi " + inUserName + " || You have " + value.points + " points");

                                //disable tag button if not it
                                if (value.isit === "notit") {
                                    $("#tagBtn").addClass("ui-state-disabled");
                                }
                            }

                            //if not current user and is not it
                            else if (contentString != uname && value.isit != "it") {
                                var marker = new google.maps.Marker({
                                    position: allUsrLoc,
                                    map: map,
                                    title: "Player"
                                });

                                google.maps.event.addListener(marker, 'click', function () {
                                    //Change selected player hidden field to match marker
                                    $("#unm_sel").val(contentString);
                                    $("#lat_sel").val(value.lat);
                                    $("#lon_sel").val(value.lon);
                                    $("#isit_sel").val(value.isit);

                                    //Change tag button to selected player's username
                                    $("#tagBtn").text("Tag " + contentString);
                                });
                            }

                            //no condition for if not current user and is it. TBD if anything will come
                        });
                    }, "json");
                } //end drawMap
        } // end loadGoogleMap
}
<div data-role="content" role="main" id="map-canvas">
<!-- Map loads here -->
</div>