【问题标题】:Change Google Marker Size on Google Maps在 Google 地图上更改 Google 标记大小
【发布时间】:2013-01-14 10:28:58
【问题描述】:

我有以下代码可以构建这样的自定义谷歌地图标记:

            mapa.markers[ind] = new google.maps.Marker({
                                position: mposition,
                                map:mapa.map,
                                title:mapa.json.markers[ind].timestamp,
                                icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld="+ind+"|000000|FFF",
                            });

使用此解决方案here,我正在尝试将此代码集成到上述代码中,但出现语法错误?我做错了什么?

null, /* size is determined at runtime */
null, /* origin is 0,0 */
null, /* anchor is bottom center of the scaled image */
new google.maps.Size(42, 68)

这是显示语法错误的更新代码:

 mapa.markers[ind] = new google.maps.Marker({
                                    position: mposition,
                                    map:mapa.map,
                                    title:mapa.json.markers[ind].timestamp,
                                    icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld="+ind+"|000000|FFF",
                                    null, /* size is determined at runtime */
                                    null, /* origin is 0,0 */
                                    null, /* anchor is bottom center of the scaled image */
                                    new google.maps.Size(42, 68)
                                });

【问题讨论】:

    标签: php google-maps


    【解决方案1】:

    你的语法不正确。

    icon object 应该这样定义:

    mapa.markers[ind] = new google.maps.Marker({
             position: mposition,
             map:mapa.map,
             title:mapa.json.markers[ind].timestamp,
             icon: {url:"http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld="+ind+"|000000|FFF",
             scaledSize:new google.maps.Size(42, 68)}
    });
    

    (感谢@andrewap 测试它和 jsfiddle)

    不需要size 属性(它在图像加载时自动设置),除非您使用精灵,这里不是这种情况。

    工作示例: http://jsfiddle.net/fUEDh/

    【讨论】:

    • size 属性是不需要的(它在图像加载时自动设置),除非您使用的是精灵,这里不是这种情况。
    • 非常感谢,很棒的回答!
    猜你喜欢
    • 1970-01-01
    • 2011-12-12
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 2013-02-12
    • 1970-01-01
    相关资源
    最近更新 更多