金溪
2016-01-11 10:09
采纳率: 100%
浏览 2.0k

怎么给百度地图添加标注啊!我的老师出错

我用百度地图添加标注点的时候是这样的
var BASEDATA = [
{title:"名称",content:"地址",point:"106.462892|29.560772",pass:1,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:0,distance_per:"0%"},

{title:"名称",content:"地址",point:"106.463306|29.562559",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:4.2,distance_per:"40%"},
{title:"名称",content:"地址",point:"106.460359|29.566125",pass:0,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:8.3,distance_per:"83%"},

{title:"名称",content:"地址",point:"106.456892|29.56801",pass:0,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:10.1,distance_per:"100%"},
{title:"名称",content:"地址",point:"106.480005|29.553075",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:9.1,distance_per:"50%"},
{title:"名称",content:"地址",point:"106.474867|29.559955",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:9.1,distance_per:"50%"}
]

    但是我现在需要显示实时的信息,所以就在后台写了一个string然后用js代码获取出来
    var a = "<%= AddPoint%>";

    然后再添加到 BASEDATA 中
     var BASEDATA = new Array();
     BASEDATA = a.split("&");
    但是标注根本没有显示出来,然后地图也不能放大缩小,而且输入地名查询出来都没有那个地图自带的标注点了,
    有木有大神知道怎么给地图添加标注点啊?不是单个的点,而且数量会变得
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 金溪 2016-01-12 03:26
    已采纳

    自己解决了,单独传了三个数组过来,然后再循环给地图添加标点,不用BASEDATA了,
    var title = "<%= Name%>";
    var sslongtitude = "<%= sLongtitude%>";
    var sslatitude = "<%= sLatitude%>";
    上面这代码我写在页面上的,在js文件里面写不了,不知道怎么回事
    var strTile = title.split(",");//标点名称
    var slongtitude = sslongtitude.split(",");//标点经度
    var slatitude = sslatitude.split(","); //标点纬度
    for (var i = 0; i < strPoint.length; i++) {
    //var point = new BMap.Point(BASEDATA[i].point.split("|")[0], BASEDATA[i].point.split("|")[1]);这行代码被取代了
    var point = new BMap.Point(slongtitude[i], slatitude[i]);
    var label = new BMap.Label(strTile[i], { "offset": new BMap.Size(9, -20) });
    }
    就是这样,然后就可以实时的显示标点了,后台可以操作

    点赞 评论
  • 你的AddPoint有什么?你组合成贴出来的json数据,如果其他格式你自己修改下

    点赞 评论
  • 金溪 2016-01-12 01:54

    用这个var BASEDATA = [
    {title:"名称",content:"地址",point:"106.462892|29.560772",pass:1,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:0,distance_per:"0%"},

    {title:"名称",content:"地址",point:"106.463306|29.562559",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:4.2,distance_per:"40%"},
    {title:"名称",content:"地址",point:"106.460359|29.566125",pass:0,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:8.3,distance_per:"83%"},

    {title:"名称",content:"地址",point:"106.456892|29.56801",pass:0,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:10.1,distance_per:"100%"},
    {title:"名称",content:"地址",point:"106.480005|29.553075",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:9.1,distance_per:"50%"},
    {title:"名称",content:"地址",point:"106.474867|29.559955",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:9.1,distance_per:"50%"}
    ]
    我alert(BASEDATA)出来的全是[object Object],[object Object],[object Object],[object Object]...
    但是用var BASEDATA = new Array();
    BASEDATA = a.split("&");
    出来的就是{{title:"名称",content:"地址",point:"106.462892|29.560772",pass:1,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:0,distance_per:"0%"},

    {title:"名称",content:"地址",point:"106.463306|29.562559",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:4.2,distance_per:"40%"},
    {title:"名称",content:"地址",point:"106.460359|29.566125",pass:0,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:8.3,distance_per:"83%"},

    {title:"名称",content:"地址",point:"106.456892|29.56801",pass:0,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:10.1,distance_per:"100%"},
    {title:"名称",content:"地址",point:"106.480005|29.553075",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:9.1,distance_per:"50%"},
    {title:"名称",content:"地址",point:"106.474867|29.559955",pass:2,icon:{w:21,h:21,l:0,t:0,x:6,lb:5},distance_total:10.1,distance_pass:9.1,distance_per:"50%"}

    这是怎么回事啊

    点赞 评论

相关推荐 更多相似问题