css 减少谷歌MapAPI中图像标记的大小[已关闭]

bvhaajcl  于 2022-12-27  发布在  其他
关注(0)|答案(1)|浏览(110)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
4天前关闭。
Improve this question
我希望在我的谷歌MapAPI中添加自定义标记。我希望使用JavaScript、HTML和CSS在大头针的中心放置一个徽标。我已经添加了一个参考,说明我希望大头针如何显示在下面。对于如何执行此操作,有任何建议或帮助吗?目前,我的标记代码如下所示,但是,我不喜欢别针本身的外观,我无法将本Map像添加到别针的中心。

  • 更新-
    我已经创建了一个我想使用的大头针的图像,但是它显示的比我喜欢的要大。我如何减小我的标记大头针的大小?
// 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',
              
              });

我试着用下面的代码替换代码,这是应该正确缩放的代码,但相反,标记消失了。

// 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)
      }
    });

3qpi33ja

3qpi33ja1#

谷歌Map提供了一种创建自定义Map的方法,其中还包括一种添加自定义图标的方法。但是,图标不会被放置在标记内。我发现解决方案是创建一个您想要的别针的图像,然后将其包含在您的代码中。我将包含代码,然后我用来编辑我的图像的大小和比例

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
    });

相关问题