简体   繁体   English

在Jquery中更改Google地图的缩放级别

[英]Change the zoom level of Google map in Jquery

I have tried the following code. 我尝试了以下代码。 Please let me know how can i change zoom level inside the autocomplete of the textbox. 请让我知道如何在文本框的自动完成功能中更改缩放级别。

    var mobileDemo = { 'center': '57.7973333,12.0502107', 'zoom': 6 };              
    $('#places').live('pageinit', function() {
        demo.add('places_1', function() {
            $('#map_canvas_3').gmap({'center': mobileDemo.center, 'zoom': mobileDemo.zoom, 'disableDefaultUI':true, 'callback': function() {
                var self = this;
                console.log(self);
                var control = self.get('control', function() {
                    $(self.el).append('<div id="control"><div><input id="places-search" class="ui-bar-d ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-d ui-autocomplete-input" type="text"/></div></div>');
                    self.autocomplete($('#places-search')[0], function(ui) {
                        self.clear('markers');
                        self.set('bounds', null);
                        $("#map_canvas_3").gmap({'zoom':15});
                        $('#map_canvas_3').gmap('refresh');
                        //self.set('zoom', 15);
                        //self.gmap('refresh');
                        self.placesSearch({ 'location': ui.item.position, 'radius': '5000' }, function(results, status) {
                            if ( status === 'OK' ) {
                                $.each(results, function(i, item) {
                                    self.addMarker({ 'id': item.id, 'position': item.geometry.location, 'bounds':true }).click(function() {
                                        self.openInfoWindow({'content': '<h4>'+item.name+'</h4>'}, this);
                                    });
                                });
                            }
                        });
                    });
                    return $('#control')[0];
                });
                self.addControl(new control(), 1);
            }});
        }).load('places_1');
    });

I have taken this code from http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-mobile.html#places I meant i have to change zoom level dynamically. 我已经从http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-mobile.html#places中获取了此代码,这意味着我必须动态更改缩放级别。 Thanks in advance. 提前致谢。

I believe that mapname.setZoom(zoom) should work where mapname is the name you gave the map when you created it and zoom the zoom level you want the map to have. 我相信mapname.setZoom(zoom)应该可以工作,其中mapname是创建地图时给它的名称,并缩放希望地图具有的缩放级别。 For future reference, check out the google maps api reference (it's not particularly great, but it'll tell you stuff like that once you've got used to using the API). 供将来参考,请查阅google maps api参考 (虽然不是特别好,但是一旦您习惯了使用API​​,它就会告诉您类似的信息)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM