﻿var geocoder = null;
var map = null;

function onLoad() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById('mapping'), { size: new GSize(300, 300) });
        map.setCenter(new GLatLng(-41.277338815652385, 173.26722621917725), 16);
        map.setUIToDefault();
    }
}

function showLocate() {
    map.clearOverlays();
    geocoder = new GClientGeocoder();
    var address = document.getElementById('txtSearch').value + "," + document.getElementById('ddlRegion').options[document.getElementById("ddlRegion").selectedIndex].text + "," + document.getElementById('ddlCountry').options[document.getElementById("ddlCountry").selectedIndex].text;
    //alert(address);
    geocoder.getLocations(address, cb_showlocations);
}

function cb_showlocations(result) {
    if (!result || result.Status.code != 200) {
        alert("Can not find this address!!Please check your region or country correct!");
    }
    else {
        var place = result.Placemark[0]
        var lat = place.Point.coordinates[1];
        var lng = place.Point.coordinates[0];
        var address = place.address;
        var point = new GLatLng(lat, lng);
        map.panTo(point);
        marker = new GMarker(point);
        map.addOverlay(marker);
        document.getElementById('txtAddress').value = address;
        document.getElementById('HLat').value = lat;
        document.getElementById('HLong').value = lng;
    }
}