How to dynamically change the centre of a google maps without erasing markers?

map.setCenter(new google.maps.LatLng(LATITUDE, LONGITUDE));

or

map.setCenter({lat: LATITUDE, lng: LONGITUDE});

This Return None Value


You can simply move the map with map.setCenter(LatLng). This method will not use any other markers and will not erase existing markers. You could also move the map via the panTo(LatLng) function. Both methods are also available after the map has been initialized.

Here is the documentation for these methods.


jOnes is right, you need to use setCenter()

function initialize()
{
    var mapDiv = document.getElementById('MapDiv');
    var map;
    var address = "Vilnius, Lithuania";
    var geocoder = new google.maps.Geocoder();
    // Get LatLng information by name
    geocoder.geocode({
        "address": address
        }, function(results, status){
                map = new google.maps.Map(mapDiv, {
                // Center map (but check status of geocoder)
                center: results[0].geometry.location,
                zoom: 8,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
            })
        });
}