简体   繁体   English

Google Maps watchposition {setzoom()}会覆盖用户缩放

[英]Google maps watchposition { setzoom() } overrides user zooming

Hey guys I've finally got my google maps working the way I want it, but I don't want my zoom to prevent the user from zooming in themselves (this keeps resetting it), I put a conditional on my setZoom to only get it to fire on first watchposition() but if I do that then the the maps sits at maximum zoom for some reason. 大家好,我终于按照自己的意愿使用了Google地图,但是我不想我的缩放阻止用户自己放大(这会不断重置),所以我在setZoom上附加了一个条件它会在第一个watchposition()上触发,但是如果我这样做,则由于某种原因,地图将以最大缩放比例放置。

function CreateMap() {
            var zoomWithoutLatLng = 13;
            var zoomWithLatLng = 15;
            Data.$paymentMap.gmap({'center': GetLatLng(), 'zoom' : zoomWithoutLatLng}).bind('init', function(evt, map) {
                Data.$paymentMap.gmap('watchPosition', function(position, status) {
                    if (status === 'OK') {
                        Data.$paymentMap.gmap({'zoom' : zoomWithLatLng});


                        var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                        var userMarker = Data.$paymentMap.gmap('get', 'markers > user' );
                        if (!userMarker) {
                            Data.$paymentMap.gmap('addMarker', { 'id': 'user', 'position': GetLatLng(), 'bounds': true) });
                        } else {
                            userMarker.setPosition(latlng);
                            map.panTo(latlng);
                        }
                    } 
                });
            });
        }        
        function GetLatLng() {
            if (google.loader.ClientLocation != null) {
                return new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
            }
        }

addMarker上的属性'bounds'将覆盖缩放设置,因此将其更改为'bounds':false

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

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