Google地图上的多个标记

时间:2014-07-25 14:40:02

标签: javascript google-maps google-maps-api-3 styling

好的SO人员,

我正在寻找与Google地图相关的一些指导。 我希望在Google地图上设置不同的样式标记。我想要的样式将受到数据库中变量帮助的影响,即酒店,咖啡厅,床和早餐。

我想根据这些值改变图标。 我已经更改了库存图标,但没有什么问题,但根据数据库中的值来更改它们是一个问题。

我在差异文件中从数据库传递了值,并可以在地图上显示它们。例如,我使用point.hotelComments收集酒店评论..所有都显示确定所以我的连接和打印很好。我有舒适度,我想影响存储在DB用户中的更改" Type"非常感谢任何帮助或指导!

我今天用来打印到地图上的代码是:

<div id="map-container" class="col-md-12"></div>
                
            <script>
                var markers = [];
                var map;

                  function initialize()
                   {

                        var mapOptions = 
                        {
                          center: new google.maps.LatLng(53.273224, -9.051864),
                          zoom: 15
                        };

                        map = new google.maps.Map(document.getElementById("map-container"),mapOptions);

                        $.ajax
                        ({
                            type: "GET",
                            dataType: "json",
                            url: "http://localhost/Project/mapdata2.php",
                            success: function (data) 
                            {
                                $.each(data,function(index,point)
                                {
                                    createMarker(point.Lat, point.Lng, map, point.hotelName, point.type, point );
                                });

                            }   
                        });
                    }
            google.maps.event.addDomListener(window, 'load', initialize);


            function createMarker(Lat, Lng, map, title, Type, point)
                {
                var latlng = new google.maps.LatLng(Lat, Lng);
                var iconBase = 'http://maps.google.com/mapfiles/ms/icons/';
                //http://maps.google.com/mapfiles/ms/icons/coffeehouse.png
                //http://maps.google.com/mapfiles/ms/icons/coffeehouse.shadow.png
                var marker = new google.maps.Marker(
                    {
                        position: latlng,
                        map: map,
                        title: title,
                        type: Type,
                        icon: iconBase + 'coffeehouse.png'

                        //icon: iconBase + 'icon_' + Type + '.png' 
                    });

                marker.setMap(map);

                markers.push(marker);



                //Adds content 
                      var contentString = '<div id="content">'+
                          '<div id="siteNotice">'+
                          '</div>'+
                          '<h1 id="firstHeading" class="leadBigBlue"> ' + point.hotelName +' </h1>'+   point.fullAddress +
                          '<div id="bodyContent">'+
                          '<p><b>' + point.hotelName + '</b>, ' +  point.hotelComments +  '  </p> ' +
                          '<p><b> Language 1 </b>   ' +  point.hotelLang +  ' </p>'+
                          '<p><b> Language 2</b>   ' +  point.hotelLang2 +  ' </p>'+
                          '<p><b> Cultures </b>   ' +  point.Cult +  ' </p>'+
                          '<p><b>Website</b> <a href="  ' +  point.localWeblink +  ' ">'+
                          'Press Here</a> </p>'+

                          '</div>'+
                          '</div>';

                      var infowindow = new google.maps.InfoWindow({
                          content: contentString
                      });

                      google.maps.event.addListener(marker, 'click', function() {
                        infowindow.open(map,marker);
                      });
                }


    </script>

1 个答案:

答案 0 :(得分:2)

针对您独特的样式问题:

我们做这样的事情......看看你是否可以跟进并实施。

...如果你有一个问题让我知道,因为有些事情发生在这个脚本之外(数据的东西)。

google.load('maps', '3', {
other_params: 'sensor=false'
});

google.setOnLoadCallback(initialize);

var markerClusterer = null;
var map = null;
var imageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&' +
'chco=FFFFFF,008CFF,000000&ext=.png';

    function initialize() {
    var center = new google.maps.LatLng(41.45,-98.87);

    var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 3,
    center: center,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var markers = [];
    for (var i = 0; i < data.count; i++) {
    spinnerUp(i);
    }

        function spinnerUp() {

            var data_mapper = data.locationstuff[i];

            var latLng = new google.maps.LatLng(data_mapper.latitude,data_mapper.longitude);

            var boxText = "<div style='border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;'>";
                boxText += data_mapper.title + "<br>" + data_mapper.address + "<br>" + data_mapper.city + ", " + data_mapper.zip;
                boxText += "</div>";

            switch (data_mapper.iconSpecial)
                {
                case 0:
                  var iconColorSpecial = "http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png";
                  break;
                case 1:
                  var iconColorSpecial = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
                  break;
                }

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

            var infowindow = new google.maps.InfoWindow({
                                                    content: boxText
                                                    ,disableAutoPan: false
                                                    ,maxWidth: 0
                                                    ,pixelOffset: new google.maps.Size(0, 0)            
                                                    ,zIndex: null
                                                    <!---,boxStyle: { 
                                                    background: "url('http://www.garylittle.ca/map/artwork/tipbox.gif') no-repeat"
                                                    ,opacity: 0.75
                                                    ,width: "280px"
                                                    }--->
                                                    ,closeBoxMargin: "10px 2px 2px 2px"
                                                    ,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
                                                    ,infoBoxClearance: new google.maps.Size(1, 1)
                                                    ,isHidden: false
                                                    ,pane: "floatPane"
                                                    ,enableEventPropagation: false});

        google.maps.event.addListener(marker, 'click', function() {infowindow.open(map, this);});
        markers.push(marker);       
        }

        var markerCluster = new MarkerClusterer(map, markers);
    }
google.maps.event.addDomListener(window, 'load', initialize);