0

我正在使用 Google Maps JavaScript API。作为地图视图的替代方案,我提供了位置的“列表”视图(我的位置是指标记):

var locloc = [];
var testContent;

var marker, i;

for (i = 0; i < locations.length; i++) {

    // UPDATE THE LIST OF LOCATIONS SECTION

    locloc.push({
        lat: locations[i][5],
        lng: locations[i][6]
    });

    testContent += '<div style="clear:both;height:200px;">'
                   + locations[i][0] + '<br>' 
                   + locations[i][5] + ',' + locations[i][6]
                   + '</div>';

    document.getElementById("search_results").innerHTML = testContent;

    var icon_image;
    icon_image = 'https://maps.gstatic.com/mapfiles/ms2/micons/subway.png';

    marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][5], locations[i][6]),
        animation: google.maps.Animation.DROP,
        icon: icon_image,
        map: map
    });

“位置列表”部分代码:

<div id="locations_list">

    <h3>List of Locations</h3>

    <div id="search_results"></div>

</div>

另外,我有一个允许按地址搜索的搜索框:

<input type="text" name="address" id="address" class="address" placeholder="Where are you coming from?" />

我想让用户搜索一个地址,然后更新“位置列表”部分,其中位置按与搜索地址的距离(最近的优先)排序。

如何使用 Google Maps JavaScript API 计算到每个标记的距离并将其输出到位置列表部分?

4

0 回答 0