Google Map API 3 Ajax调用

I am using google map API 3 and google geocoder. The problem is It's not loading the map properly I am bringing the data by ajax and calling a function showAddress(elemId, address) Where elementId is div id where the map will be rendered. Here the code for the google map

var geocoder;
var map;

    // run every mouse over
function init_gmap(elemId) {
    var mapOptions = {
        zoom: 6
    };
    map = new google.maps.Map(document.getElementById(elemId),
        mapOptions)
}

    // find the address
function showAddress(elemId, address) {
        // todo: some caching?
        init_gmap(elemId); // need to call this every time cause we're showing a new map

        if (geocoder) 
        {
            geocoder.geocode( { 'address': address}, function(results, status) {
                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
                    });

                    var infowindow = new google.maps.InfoWindow({
                    map: map,
                    position: results[0].geometry.location,
                    content: address
                    });

                    google.maps.event.trigger(map, 'resize')


                } 
                else 
                {

                    alert("Geocode was not successful for the following reason: " + status);
                }
            });
        }
}

Any suggestion?

Thank you.

Update code:

<script type="text/javascript">
//<![CDATA[

var geocoder;
var map;
var lat;
var lng;
var marker;

    // run every mouse over
function init_gmap(elemId,address) {
    geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': address}, function(results, status){
//        console.log(results[0].geometry.location.YA);
        lat = results[0].geometry.location.Ya;
        lng = results[0].geometry.location.Za;
            var mapOptions = {
                zoom: 15,
                center:  new google.maps.LatLng(lat, lng),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById(elemId),
                mapOptions)
    });

}

    // find the address
function showAddress(elemId, address) {
        // todo: some caching?
        init_gmap(elemId,address); // need to call this every time cause we're showing a new map
        marker = "marker_"+elemId;
        marker = new google.maps.Marker({
            map: map, 
            position:  new google.maps.LatLng(lat, lng)
        });

        var infowindow = new google.maps.InfoWindow({
        map: map,
        position:  new google.maps.LatLng(lat, lng),
        content: address
        });

}
</script>

In order to initialize the map you need to add center and mapTypeId to the mapOptions, (all of which are required, as mentioned in the documentation). For example:

    var mapOptions = {
        center:  new google.maps.LatLng(40.178873, -96.767578),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        zoom: 6
}