Javascript 将HTML5地理位置数据传递到express server

Javascript 将HTML5地理位置数据传递到express server,javascript,html,express,axios,Javascript,Html,Express,Axios,我也在使用HTML5地理定位api function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(patchPosition); console.log('location') } else { console.log('no location'); } } function patchPosition(position) {

我也在使用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
 });

 });

在对这个问题进行了广泛的研究之后,我一直没有找到任何可行的方法。我最初使用的是谷歌地理定位api,但只是获取服务器的位置,所以我正试图让HTML5一个工作。请提供帮助。

您是否能够从客户端获取地理位置数据?是的,position.coords.latitude等控制台日志记录正确。您的两条路线似乎不匹配。在第一个区块中,您正在向
/user
发送
POST
,在第二个区块中(您的路线),您正在等待
GET
发送
/
。您是否尝试过将路由更改为
路由器。post('/user',…
?@kqcef我应该在问题中说明,我确实需要路由器中导入和调用的apiHelpers.getResults函数的信息。get('/',…)您为什么需要在
中使用它。get(“/”…
route?似乎您需要将数据发送到特定的端点,而不是根索引。您可以将数据传递给
apiHelpers。getResults
回调以不同的路由进行。