调整 Google 地图标记图标图像的大小 [英] Resize Google Maps marker icon image

查看:69
本文介绍了调整 Google 地图标记图标图像的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将图像加载到标记的图标属性中时,它会以其原始尺寸显示,比应有的尺寸大很多.

When I load an image into the icon property of a marker it displays with its original size, which is a lot bigger than it should be.

我想将标准尺寸调整为较小的尺寸.做这个的最好方式是什么?

I want to resize to the standard to a smaller size. What is the best way to do this?

代码:

function addMyPos(latitude,longitude){
  position = new google.maps.LatLng(latitude,longitude)
  marker = new google.maps.Marker({
    position: position,
    map: map,
    icon: "../res/sit_marron.png"
  });
}

推荐答案

如果原始尺寸为 100 x 100,而您想将其缩放为 50 x 50,请使用 scaledSize 而不是 Size.

If the original size is 100 x 100 and you want to scale it to 50 x 50, use scaledSize instead of Size.

var icon = {
    url: "../res/sit_marron.png", // url
    scaledSize: new google.maps.Size(50, 50), // scaled size
    origin: new google.maps.Point(0,0), // origin
    anchor: new google.maps.Point(0, 0) // anchor
};

var marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat, lng),
    map: map,
    icon: icon
});

这篇关于调整 Google 地图标记图标图像的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆