﻿function bindGoogleMap(latCtrlId,longCtrlId) {
    var latitude = $('#' + latCtrlId).val();
    var longitude = $('#' + longCtrlId).val();

    if (latitude != null && longitude != null) {
        var mapIcon = new GIcon(G_DEFAULT_ICON);
        //mapIcon.image      = json.iconImage;
        //mapIcon.iconSize   = new GSize(37, 34);
        //mapIcon.iconAnchor = new GPoint(8, 34);
        //mapIcon.shadow     = null;

        // Set up map.
        map = new GMap2(document.getElementById('googleMap'));
        map.setCenter(new GLatLng(latitude, longitude), 15);
        map.setUIToDefault();

        var currMarker = createMarker(latitude, longitude, null, mapIcon);
        map.addOverlay(currMarker);
    }
}

function createMarker(latitude, longitude, html, mapIcon) {
    try {
        var markerLocation = new GLatLng(latitude, longitude);
        var currMarker = new GMarker(markerLocation, mapIcon);

        // Add on click popup.
        if (html != null) {
            GEvent.addListener(currMarker, 'click', function() {
                currMarker.openInfoWindowHtml(html);
            });
        }

        // Position and show.
        //map.setCenter(markerLocation, 15);
        //map.addOverlay(currMarker);
        return currMarker;
    }
    catch (exc) {
        return null;
    }
}
