Google Maps: scroll map programmatically of x pixels

时间秒杀一切 提交于 2019-12-03 03:12:52

Take a look at the projection object: http://code.google.com/apis/maps/documentation/javascript/reference.html#Projection

First you would need to get the center of the map.

var point = map.getCenter();

Convert the latlng to a point value.

var pixelpoint = projection.fromLatLngToPoint(point);

Add yourvalue to the point values.

pixelpoint.x = pixelpoint.x + yourvalue;
//or
pixelpoint.y = pixelpoint.y + yourvalue;

Convert it back to a latLng.

var newpoint = projection.fromPointToLatLng(pixelpoint);

Set the new center with the new value.

map.setCenter(newpoint);

I haven't tested the above but it should work.

I believe you are looking for this:

var panListener = google.maps.event.addListenerOnce(map, 'bounds_changed', function(event) {
                    map.panBy(0,-90);
                });

setTimeout(function() {
    google.maps.event.removeListener(panListener)
}, 2000);

In this case, it moves the map south by 90px.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!