﻿//
var map;
var latlng;
var geocoder;
var address;

//
load = function(mapcontainer, lat, lng, zoom) {
    try
    {
        if (GBrowserIsCompatible()) {
            //        map = new GMap2(mapcontainer);
            //        map.setCenter(new GLatLng(lat, lng), zoom);

            map = new GMap2(mapcontainer);
            latlng = new GLatLng(lat, lng);
            map.setCenter(latlng, zoom);
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());

            //map.addOverlay(new GMarker(latlng));

            geocoder = new GClientGeocoder();
            if (latlng != null) {
                address = latlng;
                geocoder.getLocations(latlng, showAddress);
            }
        }
    }
    catch(e)
    {
        // it works, but errors are reported.
    }
}

function showAddress(response) {
    try
    {
        map.clearOverlays();
        if (!response || response.Status.code != 200) {
            alert("Status Code:" + response.Status.code);
        } else {
            place = response.Placemark[0];
            point = new GLatLng(place.Point.coordinates[1],
                                place.Point.coordinates[0]);
            marker = new GMarker(point);
            map.addOverlay(marker);
            marker.openInfoWindowHtml(place.address);
        }
    }
    catch(e)
    {
        // it works, but errors are reported.
    }
}


