2016-12-01 68 views
0

我想要有两个标记,一个是用户的当前位置,另一个是我的应用程序中发布的位置。
用户当前位置的标记被绘制在地图上,而不是属于帖子位置的标记。
帖子包含经纬度对的感兴趣的地方的信息。地图标记在ejs文件中的脚本标记中没有显示

我呈现的EJS视图,后是这样的:

router.get('/posts/:id', function(req,res) { 
    db.post.findOne({ 
    where: { id: req.params.id} 
    }).then(function(post) { 
    res.render('posts/post_detail', {post: post}) 
    }); 
}); 

post包含经纬度信息,我想访问绘制在我的单张地图的标记。我把脚本标记在这样的EJS视图的底部:

<script> 
    var post = <%- JSON.stringify(post) %>; 
    console.log(post.latitude); 
    console.log(post.longitude); 
    L.marker([post.latitude, post.longitude]).addTo(map); 
    console.log(map) 
</script> 

经度和纬度与在数据库相同的值在控制台上打印出来。我在其他地方使用了相同的L.marker代码来在我的地图上放置标记,并且它工作得很好,但在这种情况下不会。我越来越 -

Uncaught TypeError: t.addLayer is not a function error <--

是否有另一种方法可以访问纬度和经度值在地图上绘制标记?

+1

什么是L.marker?这是您的代码中可用的功能吗?你可以显示该代码吗? – notionquest

+0

L.marker是一个leafletjs的东西。我已经使用它来绘制用户的当前位置,并且工作正常。 L.marker([latitude,longitude])。addTo(map).bindPopup(“You're here”)。openPopup(); – eugeneoei

回答

0

该映射未在该脚本标记的范围内定义。