在api链接中未定义的纬度和经度

时间:2017-11-05 01:52:51

标签: javascript api geolocation undefined

当我在我的控制台中检查时,我的经度和经度在api链接中都是未定义的。我做错了什么?。

这是我的代码

var Geo= {};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
else {
alert('Geolocation is not supported');
}


function showPosition(position) {
      Geo.lat = position.coords.latitude;
      Geo.lng = position.coords.longitude;
}
    
  // var btc = document.querySelector('#price');
//listen for clicks
window.onload = function() {
  // window.onload = function() { if want to load it immediately without d click of a btn
//make request
  var btcP = new XMLHttpRequest();
  var requestUrl ="https://fcc-weather-api.glitch.me/api/current?lat=" + Geo.lat + "&lon=" + Geo.lng + "";
  console.log(requestUrl);
  

0 个答案:

没有答案