Aeris Weather API和地理位置无法正常运行

时间:2019-05-23 14:01:35

标签: javascript jquery html geolocation

您好,我正在尝试使用HTML5 Geolocation API获取用户的位置,然后将经度和纬度传递给AerisWeather API

<div id="wxblox" class="aeris-wrapper"></div>
<script>
function cordinates() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (position) {
               return position.coords.latitude + ',' + position.coords.longitude
            }
            );
        }
        else {
            alert("Sorry, your browser does not support HTML5 geolocation.");
        }
    }
    Aeris.wxblox.setAccess('secret', 'secret');
    var view = new Aeris.wxblox.layouts.local.Main('#wxblox', {
        obs: {
            advisories: {
                enabled: true
            },
            threats: {
                enabled: true
            }
        },
        nearby: {
            request: {
                limit: 4
            }
        },
        shortterm: {
            request: {
                limit: 3
            }
        },
        forecast: {
            type: "detailed"
        },
        maps: {
            animation: {
                enabled: true,
                autoplay: false,
                alwaysShowPast: false,
                alwaysShowFuture: false,
                from: -2,
                to: 0,
                duration: 2,
                endDelay: 1,
                intervals: 10
            },
            controls: {
                layers: [
                    {
                        code: "radar",
                        title: "Radar"
                    }, {
                        code: "satellite",
                        title: "Satellite"
                    }, {
                        code: "alerts",
                        title: "Advisories"
                    }, {
                        code: "temperatures,clip-us-flat",
                        title: "Temps"
                    }
                ],
                regions: [
                    {
                        zoom: 7,
                        title: "Local"
                    }, {
                        zoom: 5,
                        title: "Regional"
                    }
                ]
            }
        }
    });
    cords = cordinates();
    view.load({
        p: cords
    });
</script>

你能告诉我我哪里错了。 API需要以这种格式传递纬度和经度-例如,纬度,经度-42.000、27.000 例如,此硬编码代码有效:

<div id="wxblox" class="aeris-wrapper"></div>
<script>
    Aeris.wxblox.setAccess('secret', 'secret');
    var view = new Aeris.wxblox.layouts.local.Main('#wxblox', {
        obs: {
            advisories: {
                enabled: true
            },
            threats: {
                enabled: true
            }
        },
        nearby: {
            request: {
                limit: 4
            }
        },
        shortterm: {
            request: {
                limit: 3
            }
        },
        forecast: {
            type: "detailed"
        },
        maps: {
            animation: {
                enabled: true,
                autoplay: false,
                alwaysShowPast: false,
                alwaysShowFuture: false,
                from: -2,
                to: 0,
                duration: 2,
                endDelay: 1,
                intervals: 10
            },
            controls: {
                layers: [
                    {
                        code: "radar",
                        title: "Radar"
                    }, {
                        code: "satellite",
                        title: "Satellite"
                    }, {
                        code: "alerts",
                        title: "Advisories"
                    }, {
                        code: "temperatures,clip-us-flat",
                        title: "Temps"
                    }
                ],
                regions: [
                    {
                        zoom: 7,
                        title: "Local"
                    }, {
                        zoom: 5,
                        title: "Regional"
                    }
                ]
            }
        }
    });
    view.load({
        p: "42.000, 27.000"
    });
</script>

0 个答案:

没有答案