如何在谷歌地图图标中更改图像的高度和宽度

时间:2017-12-07 05:46:35

标签: javascript php google-maps laravel-5.2

在此代码中,我在谷歌地图中显示多指针,但图像dosnt正常工作

<script type="text/javascript">
       var locations = <?php print_r(json_encode($deliverer)) ?>;
       var mymap = new GMaps({
         el: '#mymap',
         lat: 30.375321,
         lng: 69.345116,
         zoom:6
       });


       $.each( locations, function( index, value ){
            mymap.addMarker({
              lat: value.latitude,
              lng: value.longitude,


>  **icon: "car_marker.png";**


    icon: "car_marker.png";   ,,,,this is my image i just want to display in google map ,so how can i change the height and width in it ???
            });
      });
     </script>

1 个答案:

答案 0 :(得分:0)

您可以这样做,制作地图标记图标和对象及其配置

      var ico = '<?php echo asset("assets/images/map_marker.png"); ?>';
        var image = {
          url: ico,
          size: new google.maps.Size(71, 71),
          origin: new google.maps.Point(0, 0),
          anchor: new google.maps.Point(17, 34),
          scaledSize: new google.maps.Size(50, 50)
        };

它会将大小的标记图标传递给它,您可以根据需要进行更改,看看会发生什么。

然后你可以将它传递给这样的标记,

var marker = new google.maps.Marker({
            position: {lat: location.lat + (Math.random() -.5) / 1500, lng: location.lon + (Math.random() -.5) / 1500 },
            title: location.title,
            icon:image,
        });

谢谢。 我希望它有所帮助。