简体   繁体   English

减小谷歌地图 API 中图像标记的大小

[英]Decrease the size of image marker in google maps API

I'm looking to add custom markers to my google maps API.我正在寻找向我的谷歌地图 API 添加自定义标记。 I'm looking to place a logo in the center of the pin using javascript, HTML and csss.我希望使用 javascript、HTML 和 css 在 pin 的中心放置一个徽标。 I have added a reference of how I'd like the pin to end up looking below.我已经添加了一个参考,说明我希望 pin 最终在下面看起来如何。 Any suggestions or assistance in how to do so?有什么建议或帮助吗? Currently, my marker's code is below however, I do not like the way the pin itself looks and I am unable to add a local image to the center of the pin.目前,我的标记代码在下面,但是,我不喜欢图钉本身的外观,而且我无法将本地图像添加到图钉的中心。

--update-- - 更新 -

I have create an image of the pin that I would like to use however it displays larger then Id prefer.我已经创建了一个我想使用的图钉图像,但它显示的比我喜欢的要大。 How can I decrease the size of my marker pin?如何减小标记针的尺寸?

        // Add another marker to the map
              var marker1 = new google.maps.Marker({
                position: {lat: 40.79816525932935, lng: -73.96851680216488},
                map: map,
                icon: 'assets/img/columbiapin.png',
              
              });

Ive tried to replace the code with the code below which is what should scale properly but instead, the marker just disappears.我试图用下面的代码替换代码,这些代码应该正确缩放,但标记只是消失了。

                // Add another marker to the map
                      var marker1 = new google.maps.Marker({
      position: {lat: 40.79816525932935, lng: -73.96851680216488},
      map: map,
      icon: {
        url: 'assets/img/columbiapin.png',
        size: new google.maps.Size(40, 40),
        origin: new google.maps.Point(0, 0),
        anchor: new google.maps.Point(20, 40)
      }
    });

在此处输入图像描述

Google Maps provides a way to create custom maps which also includes a way to add custom icons. Google 地图提供了一种创建自定义地图的方法,其中还包括一种添加自定义图标的方法。 However the icons will not be placed inside of the marker.但是,图标不会放置在标记内。 I found the solution to be to create an image of the pin you'd like and then to include it in your code.我发现解决方案是创建您想要的图钉图像,然后将其包含在您的代码中。 I will include the code that I then used to edit the size and scale of my image我将包含随后用于编辑图像大小和比例的代码

        var markerColumbia = new google.maps.Marker({
      position: {lat: 40.80409446608371, lng: -73.96858177791212},
      map: map,
      icon: new google.maps.MarkerImage(
        'assets/img/columbiapin4.png',
        null, // size
        new google.maps.Point(0, 0), // origin
        null, // anchor
        new google.maps.Size(27, 40) // scaledSize
      ),
      flat: true // make the marker stay at its position on the map
    });

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

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