-1

jquery-ui-map を使用しており、ユーザーの場所にズーム レベルを設定する必要があります。現在、ユーザーを見つけてから完全にズームインしますが、さらにズームアウトしたいです。JavaScript のスキルが不足しており、答えを探していろいろ試してみましたが、何もうまくいかないようです。これがコードです...

jQuery('#map_canvas').gmap({'center': '-23.7002104, 133.8806114','zoom': 3 }).bind('init', function() { 
    jQuery('#map_canvas').gmap('getCurrentPosition', function(position, status) {
    if ( status === 'OK' ) {
    var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        jQuery.getJSON( 'http://publicaccessgolf.com.au/mapdata/', function(data) { 
            jQuery.each( data.course, function(i, course) {
                jQuery('#map_canvas').gmap('addMarker', { 
                    'position': new google.maps.LatLng(course.latitude, course.longitude),      
                }).click(function() {
                    jQuery('#map_canvas').gmap('openInfoWindow', { 'content': '<div align="left"><p style="color:#000000;"><a href="http://publicaccessgolf.com.au/' + course.slug + '" >' + course.name + '</a><br />' + course.address + '<br />' + course.contact + '</p></div>' }, this);
                });
            });
        });
        jQuery('#map_canvas').gmap('addMarker', {'position': clientPosition, 'zoom': 3});

    }
    });     
});

さて、私はそれを解決しました、正しいコードは以下です。ズームの代わりに maxZoom を使用

jQuery('#map_canvas').gmap({'center': '-23.7002104, 133.8806114','maxZoom': 11}).bind('init', function() { 
    jQuery('#map_canvas').gmap('getCurrentPosition', function(position, status) {
    if ( status === 'OK' ) {
    var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        jQuery.getJSON( 'http://publicaccessgolf.com.au/mapdata/', function(data) { 
            jQuery.each( data.course, function(i, course) {
                jQuery('#map_canvas').gmap('addMarker', { 
                    'position': new google.maps.LatLng(course.latitude, course.longitude),      
                }).click(function() {
                    jQuery('#map_canvas').gmap('openInfoWindow', { 'content': '<div align="left"><p style="color:#000000;"><a href="http://publicaccessgolf.com.au/' + course.slug + '" >' + course.name + '</a><br />' + course.address + '<br />' + course.contact + '</p></div>' }, this);
                });
            });
        });
        jQuery('#map_canvas').gmap('addMarker', {'position': clientPosition, 'bounds':true});

    }
    });     
}); 
4

1 に答える 1

0

このような問題が発生したら、APIドキュメントを読んで、これがうまくいく方法を見つけました。次の行を置き換えることができます。

jQuery('#map_canvas').gmap('addMarker', {'position': clientPosition, 'zoom': 3});

これとともに:

 jQuery('#map_canvas').gmap('addMarker', {'position': clientPosition});
 jQuery('#map_canvas').gmap('option','zoom',3);
 jQuery('#map_canvas').gmap('option','center',new google.maps.LatLng(position.coords.latitude, position.coords.longitude));

これを試して、これが役立つかどうかを確認してください。

于 2012-12-21T08:02:57.720 に答える