从数据对象设置多个标记谷歌地图

时间:2018-04-23 05:16:23

标签: javascript json google-maps

每个人,

我有这样的代码

var locations = [
    [-33.890542, 151.274856, 4],
    [-33.923036, 151.259052, 5]
];

var res = {
    destination: {lat: -6.3207993, lng: 106.7261287},
    departure: {lat: -6.170885, lng: 106.813184}
}

var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 10,
    center: new google.maps.LatLng(-33.92, 151.25),
    mapTypeId: google.maps.MapTypeId.ROADMAP
});

var marker, i;

for (i = 0; i < 2; i++) { 
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][0], locations[i][1]),
        map: map
    });
}

并且我想在Google地图上显示数据对象 res 作为标记,如何将 res 数据对象显示到数组以用于创建标记?请有人帮帮我..

1 个答案:

答案 0 :(得分:2)

只需迭代<div id="box" class="min"> <span id ="toggle" class="fa fa-window-restore"> <b>Open Dialog</b> </span> <form action="/conversations/3/reply" accept-charset="UTF-8" method="post"> <input name="utf8" type="hidden" value="&#x2713;" /> <input type="hidden" name="authenticity_token" value="VgKXI1p4MumSlvZF51pbXYKMMRLFKs0Us4NUB2+O7VZalzk++QDNQ5SsQMzvt4HlgUnlMa3ux54IDc3R/tGZhA==" /> <textarea name="body" id="body" cols="3" class="form-control" placeholder="Type something..." required="required"></textarea> <button name="button" type="submit" class="btn_green">Send Message</button> </form> </div> 的值即可创建新标记

res