Rob
Rob

Reputation: 2779

Get map type of google map with API

This is the code my co-worker wrote to get the map up and working. I've got a few issues.

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

Elsewhere on the page, I need to display what kind of map is currently up. There's a button to press that switches between a roadmap and streetview. Another thing is that we're loading the map into a div that should be hidden by default. But when we call mapstart(params), it shows the map. We'd like the map to load and be hidden and then display when we show that that div and hide other divs. Currently I have it so the button that you press to show the map div loads the map, but I'd rather not reload the map every time the button is pressed.

Upvotes: 2

Views: 2313

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117314

$('selector').gmap3({action:'get'}).getMapTypeId()

http://code.google.com/intl/en/apis/maps/documentation/javascript/reference.html#Map

Upvotes: 3

Related Questions