

var map ;
var geocoder;
var defaultGpoint;
var opt;



 
  function createMap(lat, lon, type){
      opt = { icon: mrplaceIcons[type] };
      if (GBrowserIsCompatible()) {
        map= new GMap2(document.getElementById("googlemap"));
	//	map.addControl(new GLargeMapControl());
     // map.addControl(new GMapTypeControl());
     
     defaultGpoint=new GLatLng(lat, lon);
     map.setCenter(defaultGpoint,14);
     geocoder = new GClientGeocoder();


    
	var marker = new GMarker(defaultGpoint, opt);
        
     map.addOverlay(marker);
        //map.setCenter(new GLatLng(37.4419, -122.1419), 13);
       // showLocation("kathmandu");
      }
  }
 

  function createMap2(lat, lon, type){
      opt = { icon: mrplaceIcons[type] };
      if (GBrowserIsCompatible()) {
        map= new GMap2(document.getElementById("googlemap2"));
	//	map.addControl(new GLargeMapControl());
     // map.addControl(new GMapTypeControl());
     
     defaultGpoint=new GLatLng(lat, lon);
     map.setCenter(defaultGpoint,14);
     geocoder = new GClientGeocoder();


    
	var marker = new GMarker(defaultGpoint, opt);
        
     map.addOverlay(marker);
        //map.setCenter(new GLatLng(37.4419, -122.1419), 13);
       // showLocation("kathmandu");
      }
  }
  

    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) {
     // map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Op basis van dit adres kunnen we geen locatie vaststellen.");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        marker1 = new GMarker(defaultGpoint);
        map.addOverlay(marker);
       // map.addOverlay(marker1);
        drawLine(defaultGpoint, point);
        //map.setCenter(point,8);


      }
    }

    // showLocation() is called when you click on the Search button
    // in the form.  If geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation(address) {
      geocoder.getLocations(address, addAddressToMap);
    }
    
    function getMapLocation(address,callback) {
    	geocoder = new GClientGeocoder();
        geocoder.getLocations(address, callback);
    }


    function drawLine(startGPoint, endGPoint){
       var myArray = new Array(startGPoint, endGPoint);
       var line = new GPolyline(myArray);
       map.addOverlay(line);

    }
    
    

 

