谷歌浏览器的地理位置错误

时间:2016-08-22 16:53:30

标签: javascript jquery json

所以,这是页面:http://codepen.io/sterg/full/NAVWay/
它适用于Mozzila和Edge,但它不适用于Chrome 任何想法为什么会这样?

这是我用来获取地理位置数据(纬度经度)的javascript:

$(document).ready(function() {



if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    //$(".test1").append("latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude);
    var ur="http://api.openweathermap.org/data/2.5/weather?lat="+position.coords.latitude+"&lon="+position.coords.longitude+"&appid=18c7e2b6b0150a8f1d2c6b946e065697";
        $.getJSON(ur, function(json) {
       // $(".test2").append(JSON.stringify(json));
        $(".location").append(json.name+","+json.sys.country);
        $(".tempe").html(   (json.main.temp-273.15).toFixed() + " &#8451; " );

        $(".option2").click(function(){
        $(".tempe").html(   ((json.main.temp-273.15)*(9/5)+32).toFixed() + " &#8457; " );
        });
        $(".option1").click(function(){
        $(".tempe").html(   (json.main.temp-273.15).toFixed() + " &#8451; " );
        });

        if(json.weather[0].main=="Clear"){
            $('body').css({
          'background': 'url(http://eskipaper.com/images/sunny-day-4.jpg) no-repeat center center fixed',
          '-webkit-background-size': 'cover',
          '-moz-background-size': 'cover',
          '-o-background-size': 'cover',
          'background-size': 'cover',
          'font-family':'Baloo Paaji',
           'color': '#7a5cfe',
            'font-size':'30px'

        });
        }else if (json.weather[0].main=="Clouds") {
            $('body').css({
          'background': 'url(http://constantine.typepad.com/.a/6a0120a7fc3be9970b01bb08d49380970d-pi) no-repeat center center fixed',
          '-webkit-background-size': 'cover',
          '-moz-background-size': 'cover',
          '-o-background-size': 'cover',
          'background-size': 'cover',
           'font-family':'Baloo Paaji',
           'color': '#7a5cfe',
            'font-size':'30px'
        });

        }else if (json.weather[0].main=="Rain") {
            $('body').css({
          'background': 'url(https://images4.alphacoders.com/235/235564.jpg) no-repeat center center fixed',
          '-webkit-background-size': 'cover',
          '-moz-background-size': 'cover',
          '-o-background-size': 'cover',
          'background-size': 'cover',
            'font-family':'Baloo Paaji',
           'color': '#7a5cfe',
            'font-size':'30px'
        });
        }

//https://images4.alphacoders.com/235/235564.jpg
//http://constantine.typepad.com/.a/6a0120a7fc3be9970b01bb08d49380970d-pi
        });

  });


}



});

0 个答案:

没有答案