在谷歌地图中分配不同的标记

Assigning Different Markers in Google Maps

本文关键字:谷歌地图 分配      更新时间:2023-09-26

我正在使用Google地图Classic ASP进行一个项目。该地图具有从数据库中拉出的各种位置,这很好并且工作得很好。

我需要做的是根据属性类型等分配不同的标记。

我已经搜索过,找不到该怎么做,因为我的 javascript 不是很好。任何指示都将不胜感激。我确实需要使用以下代码,但进行了调整。

PS我已经删除了ASP分隔符,因为代码似乎正在尝试执行:-)

var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
new google.maps.Size(32, 32), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
    var pt = new google.maps.LatLng(lat, lng);
    bounds.extend(pt);
    var marker = new google.maps.Marker({
        position: pt,
        icon: '../img/map/Bar.png',
        map: map
    });
    var popup = new google.maps.InfoWindow({
        content: info,
        maxWidth: 500
    });
    google.maps.event.addListener(marker, "click", function() {
        if (currentPopup != null) {
            currentPopup.close();
            currentPopup = null;
        }
        popup.open(map, marker);
        currentPopup = popup;
    });
    google.maps.event.addListener(popup, "closeclick", function() {
        map.panTo(center);
        currentPopup = null;
    });
}
function initMap() {
    map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(0, 0),
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: false,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
        },
        navigationControl: true,
        navigationControlOptions: {
            style: google.maps.NavigationControlStyle.SMALL
        }
    });
    sSQL = "select id, name, province, lat, lng, map_include, map_type from resort where (map_include = 'Playa Del Ingles' and live = 1) order by id asc"
    Set ors = cn.Execute(sSql)
    do while not ors.eof
    //loop does stuff here which I won't bore you about
    response.write "addMarker(" & lat & "," & lon & ",'<h4 style=""margin-bottom:10px"">" & name & "</h4><img class=""prop_img"" src=""../resorts/" & prop_id & "/1.jpg""><div style=""width:300;float:left""><strong>" & prop_type & "</strong><br />" & province & "<br /><a href=""../" & page_url & "/resort.asp?hid=" & prop_id & """>More Details</a></div>')" & VbCrLf & ";"
    ors.movenext
    loop
    center = bounds.getCenter();
    map.fitBounds(bounds);
}

在不更改大量代码的情况下,我会更改 addMarker 方法以包含"icon"参数,因此请更改

function addMarker(lat, lng, info) {

function addMarker(icon, lat, lng, info) {

然后从新标记更改"图标"属性,更改

var marker = new google.maps.Marker({
    position: pt,
    icon: '../img/map/Bar.png',
    map: map
});

var marker = new google.maps.Marker({
    position: pt,
    icon: icon,
    map: map
});

最后更改 addMarker 调用

addMarker(" & lat & "," & lon & ", ...

addMarker(YourIconURLHere, " & lat & "," & lon & ", ...

您需要根据从SQL查询中获得的属性(或我认为map_type)更改图标URL。