使用API​​获取谷歌地图的地图类型

时间:2012-03-06 16:01:40

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

这是我的同事为了使地图正常工作而编写的代码。我有一些问题。

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加载地图,但每次按下按钮时我都不会重新加载地图。

1 个答案:

答案 0 :(得分:3)