2012-02-21 16 views
5

सेट करने के लिए कैसे करें मेरे पास निम्न कोड ठीक काम कर रहा है, लेकिन मैं ज़ूम स्तर जोड़ने में असमर्थ हूं। docs के अनुसार यह 'option', 'zoom', 7 के साथ काम करना चाहिए लेकिन यह एक त्रुटि देता है: "$("#map_canvas").gmap("option", "zoom", 7).bind is not a function"jquery-ui-map ज़ूम स्तर

कार्य कोड, संस ज़ूम, संपादित। ज़ूम हमेशा 1.

$("#map_trigger").click(function(){ 
     var prop_id = $("#map_canvas").attr("rel"); 
     $('#map_canvas').gmap({'zoom':6}).bind('init', function(evt, map) { 
      $.getJSON(basepath+'properties/get_gps_coords/'+prop_id, function(data) { 
       $.each(data.markers, function(i, m) { 
        lat = m.latitude; 
        longitude = m.longitude; 
        $('#map_canvas').gmap(
         'addMarker', { 'position': new google.maps.LatLng(lat, m.longitude), 'bounds':true } 
        ); 
       }); 
      }); 
     }); 
    }); 

मैं इस स्निपेट में ज़ूम स्तर कैसे जोड़ सकता हूं?

उत्तर

8

उपयोग:

$("#map_canvas").gmap({'zoom':7}) 

विकल्प-विधि जब नक्शा पहले से ही आरंभ नहीं हो जाता है और एक jQuery-वस्तु नहीं लौटेगा इस्तेमाल किया जा सकता है, इसलिए यह chainable नहीं कर रहा है (क्या त्रुटि आप मिल गया समझा जाएगा)।

+1

कहां? मैंने विभिन्न स्थानों में कोशिश की, आपके कोड की दूसरी पंक्ति पर – stef

+0

कोई बदलाव नहीं,'बिंद ('init', ' –

+0

ऊपर अपना कोड अपडेट किया गया है लेकिन ज़ूम अभी भी अधिकतम – stef

10

इस कोड मेरे लिए काम करता है:

<!doctype html> 
<html> 
    <head> 
     <meta http-equiv="content-language" content="es"> 
     <meta charset="utf-8"> 

     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
     <script type="text/javascript" src="js/jquery-1.7.1/jquery.min.js"></script> 
     <script type="text/javascript" src="../ui/jquery.ui.map.js"></script> 

    </head> 
    <body> 
     <div style="height: 500px; width:500px;" id="map_canvas"></div> 
     <button id="btnChangeZoom">change zoom</button> 
     <script type="text/javascript"> 
     $(function() { 
      $('#map_canvas').gmap({ 'center': '40.33238,-3.76546','scrollwheel':false}); 
      $('#map_canvas').gmap('option', 'mapTypeId', google.maps.MapTypeId.SATELLITE); 
      $('#map_canvas').gmap('option', 'zoom', 17); 
      }); 

     $("#btnChangeZoom").click(function(){changeZoom()}); 

     function changeZoom(){ 
      $('#map_canvas').gmap('option', 'zoom', 10); 
     } 
     </script> 
    </body> 
</html> 
2

यो नक्शे को केंद्रित करने के लिए और फिर इसे ज़ूम की जरूरत है। यहां कोड का एक नमूना है

$('#map_canvas').gmap({'center': '43.1502, 25.02083'}) 
$('#map_canvas').gmap('option', 'zoom', 10); 
$('#map_canvas').gmap('addMarker', {'position': '43.1502, 25.02083', 'icon': '/picnic/img/Pin.png'}).click(function() { 
    //$('#map_canvas').gmap('openInfoWindow', {'content': 'Hello World!'}, this); 
}); 
संबंधित मुद्दे