将数据从服务器发送到js文件.让Passport在谷歌地图信息框上显示Facebook的图片

sending data from server to a js file.. getting Passport to display Facebook image on Google maps infobox

本文关键字:信息 谷歌地图 显示 Facebook Passport 服务器 数据 文件 js      更新时间:2023-09-26

我使用passport.js将用户登录到谷歌地图API。当你登录时,它会进行地理定位,并在地图上标记你的facebook图像和名字。然而,我正在努力做到这一点!

包含所有map逻辑的map.js无法看到包含所有用户逻辑的server.js。所以Map.js不知道用户是什么

下面我们设法对它进行了硬编码。我们如何让它充满活力?完整回购网址:https://github.com/5-minute-catchup/ANEWREPO谢谢你

if(navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            new google.maps.InfoWindow({
              map: map,
              position: pos,
              content: profile.id + 'user.name <IMG BORDER="0" ALIGN="Left" SRC="https://graph.facebook.com/10153052143439442/picture"> <br>Phoebe '
            });
            map.setCenter(pos);

当用户登录时,我们将图像保存到我们自己的mongoDB中。然而,我们不能将此添加到标记并使其返回…我们对out数据库返回图像的调用是

<img src="<%= user.image %>">

我如何将服务器所知道的关于用户的信息传递给map.js ?

map.js中的解决方案是:

  var getUser = document.getElementById("map-canvas");
new google.maps.InfoWindow({
          map: map,
          position: pos,
          content: '<IMG BORDER="0" ALIGN="Left" SRC=' + getUser.dataset.image + '>'
        });

and in index.ejs:

<div id="map-canvas" data-name='<%= user.name %>' data-image=<%= user.image %>>
        </div>