Google maps panby(x,y)在谷歌地图代码中的位置

Google maps panby(x,y)在谷歌地图代码中的位置,google-maps,Google Maps,几天以来,我一次又一次地试图找到合适的地方,但没有任何运气。 在下面的google maps代码中,我找不到将map.panby(x,y)放在何处,以使标记更靠近右侧 如果有人能帮助我,那就太好了 最好的 var地理编码器; var映射; 函数初始化(){ geocoder=新的google.maps.geocoder(); var latlng=新的google.maps.latlng(52.5200066,13.404954); 变量映射选项={ 缩放:6, 滚轮:错误, 导航控制:错误,

几天以来,我一次又一次地试图找到合适的地方,但没有任何运气。 在下面的google maps代码中,我找不到将
map.panby(x,y)
放在何处,以使标记更靠近右侧

如果有人能帮助我,那就太好了

最好的


var地理编码器;
var映射;
函数初始化(){
geocoder=新的google.maps.geocoder();
var latlng=新的google.maps.latlng(52.5200066,13.404954);
变量映射选项={
缩放:6,
滚轮:错误,
导航控制:错误,
mapTypeControl:false,
scaleControl:false,
可拖动:错误,
动物控制:对,
ZoomControl选项:{
样式:google.maps.ZoomControlStyle.SMALL,
位置:google.maps.ControlPosition.LEFT_CENTER
},
街景控制:错误,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP,
风格:[
{
“featureType”:“administration.country”,
“elementType”:“几何体”,
“造型师”:[
{“重量”:1.2},
{“颜色”:“#dd4b39”}
]
},{
“功能类型”:“管理”,
“造型师”:[
{“可见性”:“简化”}
]
},{
“featureType”:“administration.country”,
“造型师”:[
{“可见性”:“在”}
]
},{
“featureType”:“administration.locality”,
“造型师”:[
{“可见性”:“在”}
]
}
]
}
map=new google.maps.map(document.getElementById('user-map-canvas'),mapOptions);
}
函数showAddress(地址){
geocoder.geocode({'address':address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
var marker=new google.maps.marker({
地图:地图,
位置:结果[0]。几何体。位置
});
}否则{
警报(“地址:folgendem Grund nicht gefunden werden:+状态”);
}
google.maps.event.addListener(标记,'click',function(){//将单击侦听器添加到标记中
window.location='/freiwillige/?s=';//链接标记的URL(即Google Places列表)
});
});
}      
jQuery(document).ready(函数(){initialize();showAddress(“”);});

您应该能够在地图实例化后的任何位置放置panby,因此在您给出的示例中:

map = new google.maps.Map(document.getElementById('user-map-canvas'), mapOptions);
map.panby(x, y);
应该可以很好地工作

请注意,此函数平移贴图,它不会相对于平铺移动标记,我想这是您想要的吗

编辑您应该能够在执行过程中的任何时候进行调用。例如,要在地理编码请求后稍微偏移地图,可以执行以下操作:

if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map, 
        position: results[0].geometry.location
    });
    map.panby(x, y);
  }
编辑确定,这样我就用我提到的更改修改了您的原始代码。试试这个:

<script type="text/javascript">
    var geocoder;
    var map;
    function initialize() {
    geocoder = new google.maps.Geocoder();
    var mapOptions = {
        zoom: 6,
        scrollwheel: false,
        navigationControl: false,
        mapTypeControl: false,
        scaleControl: false,
        draggable: false,
        zoomControl: true,
        zoomControlOptions: {
            style: google.maps.ZoomControlStyle.SMALL,
            position: google.maps.ControlPosition.LEFT_CENTER
        },
        streetViewControl:false,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: [
        {
            "featureType": "administrative.country",
            "elementType": "geometry",
            "stylers": [
            { "weight": 1.2 },
            { "color": "#dd4b39" }
            ]
        },{
            "featureType": "administrative",
            "stylers": [
            { "visibility": "simplified" }
            ]
        },{
            "featureType": "administrative.country",
            "stylers": [
            { "visibility": "on" }
            ]
        },{
            "featureType": "administrative.locality",
            "stylers": [
            { "visibility": "on" }
            ]
        }
        ]
    }

    map = new google.maps.Map(document.getElementById('user-map-canvas'), mapOptions);   
    }

    function showAddress(address) {
        geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var marker = new google.maps.Marker({
                    map: map, 
                    position: results[0].geometry.location
                });
                map.setCenter(results[0].geometry.location);
                map.panby(x, y);
            } 
            else 
            {
                alert("Adresse konnte aus folgendem Grund nicht gefunden werden: " + status);
            }



            google.maps.event.addListener(marker, 'click', function() { // Add a Click Listener to our marker 
                window.location='/freiwillige/?s=<?php echo $country ?>'; // URL to Link Marker to (i.e Google Places Listing)
            });
        });

    }      

    jQuery(document).ready( function() { initialize(); showAddress('<?php echo $address ?>'); } );
</script>

var地理编码器;
var映射;
函数初始化(){
geocoder=新的google.maps.geocoder();
变量映射选项={
缩放:6,
滚轮:错误,
导航控制:错误,
mapTypeControl:false,
scaleControl:false,
可拖动:错误,
动物控制:对,
ZoomControl选项:{
样式:google.maps.ZoomControlStyle.SMALL,
位置:google.maps.ControlPosition.LEFT_CENTER
},
街景控制:错误,
mapTypeId:google.maps.mapTypeId.ROADMAP,
风格:[
{
“featureType”:“administration.country”,
“elementType”:“几何体”,
“造型师”:[
{“重量”:1.2},
{“颜色”:“#dd4b39”}
]
},{
“功能类型”:“管理”,
“造型师”:[
{“可见性”:“简化”}
]
},{
“featureType”:“administration.country”,
“造型师”:[
{“可见性”:“在”}
]
},{
“featureType”:“administration.locality”,
“造型师”:[
{“可见性”:“在”}
]
}
]
}
map=new google.maps.map(document.getElementById('user-map-canvas'),mapOptions);
}
函数showAddress(地址){
geocoder.geocode({'address':address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
var marker=new google.maps.marker({
地图:地图,
位置:结果[0]。几何体。位置
});
map.setCenter(结果[0].geometry.location);
潘比地图(x,y);
} 
其他的
{
警报(“地址:folgendem Grund nicht gefunden werden:+状态”);
}
google.maps.event.addListener(标记,'click',function(){//将单击侦听器添加到标记中
window.location='/freiwillige/?s=';//链接标记的URL(即Google Places列表)
});
});
}      
jQuery(document).ready(函数(){initialize();showAddress(“”);});
我已经删除了地图的原始居中(以及变量latlng,您在其他任何地方都不使用它),然后在地理代码请求完成后居中并偏移。手指。交叉


如果panby仍然无法工作,请编辑查看答案,但我看不到代码有任何问题。

Wow!这让我又向前迈进了一大步!谢谢……:)但是现在地图的中心点是这里定义的:
var latlng=new google.maps.latlng(52.520006613.404954)而不是标记。有没有办法解决这个问题。你想让地图在初始化时还是在地理编码请求后居中于标记?好吧,我只想在加载页面时它居中于标记,但标记应该稍微偏右一点。;)非常感谢,这会让我发疯的!见第二版
<script type="text/javascript">
    var geocoder;
    var map;
    function initialize() {
    geocoder = new google.maps.Geocoder();
    var mapOptions = {
        zoom: 6,
        scrollwheel: false,
        navigationControl: false,
        mapTypeControl: false,
        scaleControl: false,
        draggable: false,
        zoomControl: true,
        zoomControlOptions: {
            style: google.maps.ZoomControlStyle.SMALL,
            position: google.maps.ControlPosition.LEFT_CENTER
        },
        streetViewControl:false,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: [
        {
            "featureType": "administrative.country",
            "elementType": "geometry",
            "stylers": [
            { "weight": 1.2 },
            { "color": "#dd4b39" }
            ]
        },{
            "featureType": "administrative",
            "stylers": [
            { "visibility": "simplified" }
            ]
        },{
            "featureType": "administrative.country",
            "stylers": [
            { "visibility": "on" }
            ]
        },{
            "featureType": "administrative.locality",
            "stylers": [
            { "visibility": "on" }
            ]
        }
        ]
    }

    map = new google.maps.Map(document.getElementById('user-map-canvas'), mapOptions);   
    }

    function showAddress(address) {
        geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var marker = new google.maps.Marker({
                    map: map, 
                    position: results[0].geometry.location
                });
                map.setCenter(results[0].geometry.location);
                map.panby(x, y);
            } 
            else 
            {
                alert("Adresse konnte aus folgendem Grund nicht gefunden werden: " + status);
            }



            google.maps.event.addListener(marker, 'click', function() { // Add a Click Listener to our marker 
                window.location='/freiwillige/?s=<?php echo $country ?>'; // URL to Link Marker to (i.e Google Places Listing)
            });
        });

    }      

    jQuery(document).ready( function() { initialize(); showAddress('<?php echo $address ?>'); } );
</script>