将HTML5地理位置数据传递到快速服务器

时间:2017-05-23 00:05:19

标签: javascript html5 express axios

我正在使用HTML5地理位置api。

function getLocation() {
if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(patchPosition);
  console.log('location')
    } else {
   console.log('no location');
 }
   }

 function patchPosition(position) {
      axios.post('/user', {
           lat: position.coords.latitude,
           lng: position.coords.longitude
    }).then((res) => {
        console.log("geolocation", res.config.data)
      }).catch( function(error) {
    if (error.response) {
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    }
  })
}


 getLocation();

我试图将纬度和经度传回这条快车道。

router.get('/', authHelpers.loginRequired, apiHelpers.getResults, (req, 
res, next) => {
  console.log('places ======>' + res);
  res.render('user/index', {
  user: req.user.dataValues,
places: res.locals.places,
locations: res.locals.locations,
userLat: res.locals.lat,
userLong: res.locals.long
 });

 });

经过对这个问题的广泛研究,我无法得到任何工作。我最初使用googles geolocation api但只获取服务器的位置,所以我试图让HTML5工作。请帮忙。

0 个答案:

没有答案
相关问题