繁体   English   中英

谷歌地图中的标记图像取决于列值

[英]Marker image in google maps depending on column value

我找到了一个脚本,可以在Google地图中创建标记。 标记是从数据库加载的。 该脚本的一部分如下:

    //Load Markers from the XML File, Check (map_process.php)
        $.get("map_process.php", function (data) {
            $(data).find("marker").each(function () {
                  var name      = $(this).attr('name');
                  var address   = '<p>'+ $(this).attr('address') +'</p>';
                  var type      = $(this).attr('type');
                  var door      = $(this).attr('door');
                  var point     = new google.maps.LatLng(parseFloat($(this).attr('lat')),parseFloat($(this).attr('lng')));
                  create_marker(point, name, address, false, false, false, "http://www.example.com/marker/icons/A.png");
            });
        }); 

通过创建标记,例如A,B和C,我可以选择3种“类型”。所有标记现在都由A.png显示。 我想知道是否可以根据类型制作标记图像。 如果type是A,则比A.png;如果type是B,则比B.png;如果type是C,则比C.png。

有人能帮我吗?

也许一些if statements

//Load Markers from the XML File, Check (map_process.php)
        $.get("map_process.php", function (data) {
            $(data).find("marker").each(function () {
                  var name      = $(this).attr('name');
                  var address   = '<p>'+ $(this).attr('address') +'</p>';
                  var type      = $(this).attr('type');
                  var door      = $(this).attr('door');
                  var point     = new google.maps.LatLng(parseFloat($(this).attr('lat')),parseFloat($(this).attr('lng')));
               if(type == "A"){
                 create_marker(point, name, address, false, false, false, "http://www.example.com/marker/icons/A.png");
               } else if(type ="B"){
                 create_marker(point, name, address, false, false, false, "http://www.example.com/marker/icons/B.png");
               }           
            });
        }); 

只需在$.get内放入if statement然后根据结果执行create_marker

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM