成功时出错callbackId:GeolocationXXXX:ReferenceError:找不到变量:$

时间:2016-08-05 10:16:47

标签: javascript cordova

似乎无法解决这个问题。有人可以帮忙吗?系统保持返回成功中的错误callbackId:GeolocationXXXX:ReferenceError:找不到变量:$

以下是代码:

<script>
        document.addEventListener("deviceready", onDeviceReady, false);
        function onDeviceReady() {
        console.log("navigator.geolocation works well");
        }


        function getWeatherLocation() {

        navigator.geolocation.getCurrentPosition
        (onWeatherSuccess, onWeatherError, { enableHighAccuracy: true });
        }
        // Success callback for get geo coordinates

        var onWeatherSuccess = function (position) {

            Latitude = position.coords.latitude;
            Longitude = position.coords.longitude;

            getWeather(Latitude, Longitude);
        }

        function getWeather(latitude, longitude) {

            var OpenWeatherAppKey = "2c75f3c07a9c883910dcde8c30d91b56";

            var queryString =
            'http://api.openweathermap.org'
            + latitude + '&lon=' + longitude + '&appid=' + OpenWeatherAppKey + '&units=imperial';

            $.getJSON(queryString, function (results) {

                if (results.weather.length) {

                     $.getJSON(queryString, function (results) {

                        if (results.weather.length) {

                            $('#description').text(results.name);
                            $('#temp').text(results.main.temp);
                            $('#wind').text(results.wind.speed);
                            $('#humidity').text(results.main.humidity);
                            $('#visibility').text(results.weather[0].main);

                            var sunriseDate = new Date(results.sys.sunrise);
                            $('#sunrise').text(sunriseDate.toLocaleTimeString());

                            var sunsetDate = new Date(results.sys.sunrise);
                            $('#sunset').text(sunsetDate.toLocaleTimeString());
                        }

                    });
                }
            }).fail(function () {
                console.log("error getting location");
            });
        }


        function onWeatherError(error) {
            console.log('code: ' + error.code + '\n' +
             'message: ' + error.message + '\n');
        }

</script>

此代码来自cordova apache GetWeatherForecast文档

0 个答案:

没有答案