【问题标题】:Get map type of google map with API使用 API 获取谷歌地图的地图类型
【发布时间】:2012-03-06 16:01:39
【问题描述】:

这是我的同事编写的用于启动地图并使其正常工作的代码。我有一些问题。

function mapstart(maptype,streetview,fulladdress){
    streetdisplay = false;
    $(function() {
        addr = fulladdress;
        bool = true;
        $('#'+maptype).gmap3({
            action: 'getLatLng',
            address: fulladdress,
            callback: function(result){
                if (result){
                    $(this).gmap3({action: 'setCenter', args:[ result[0].geometry.location ]});
                    drawmap(maptype,streetview);
                } else {
                    bool = false;
                    alert('Incorrect address so map cannot be drawn !');
                }
            }
        });
         $('#'+maptype).show().gmap3().css('border', '1px solid #000000');
    });
}
function drawmap(temp,tempstreet){
    if(bool == true){
         $('#'+temp).gmap3({
            action: 'addMarker',
            address: addr,
            marker:{},
            map:{
                center: true,
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
        }); 
        $('#'+tempstreet).click(function(){
            countmap++;
                if (countmap%2 == 0)
                    streetdisplay = false;
                else
                    streetdisplay = true;
             $('#'+temp).gmap3({
                action:'getStreetView',
                callback:function(panorama){
                    var visible = panorama.getVisible();
                    if (visible) {
                        panorama.setVisible(false);
                    } else {
                        var map = $(this).gmap3('get');
                        panorama.setPosition(map.getCenter());
                        panorama.setPov({
                            heading: 265,
                            zoom:1,
                            pitch:0
                        });
                        panorama.setVisible(true);
                    }
                }
            });
        }); 
    } else {
        $('#'+temp).gmap3;
    }
    $('#'+temp).show().gmap3().css('border', '1px solid #000000');
}

在页面的其他地方,我需要显示当前正在运行的地图类型。有一个按钮可以在路线图和街景之间切换。另一件事是我们将地图加载到默认情况下应该隐藏的 div 中。但是当我们调用 mapstart(params) 时,它会显示地图。我们希望地图加载并隐藏,然后在我们显示该 div 并隐藏其他 div 时显示。目前我有它,所以您按下以显示地图 div 的按钮会加载地图,但我不想每次按下按钮时都重新加载地图。

【问题讨论】:

    标签: javascript google-maps google-maps-api-3 jquery-gmap3


    【解决方案1】:

    【讨论】:

    • 我知道 getMapTypeId() 函数,但我不知道如何在这里应用它。我在代码中的任何地方都看不到任何特定的地图对象。 :/ 我会再检查一下。
    • 见上面如何,gmap3的get-action在没有存储名称的情况下返回google.maps.Map
    • 好的,谢谢。它显示了路线图,我会看看发生了什么。
    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多