    //Begins 
     function loadScript() {
     	var script = document.createElement('script');
     	script.type = 'text/javascript';
     	script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyDfW9YcvZCJafB-k2c-SBaBhGOvcy5f148' +
     		'&callback=initialize';
     	document.body.appendChild(script);
     }

     window.onload = loadScript;
     //var executed=false;
     var projectpng='/static/images/google_maps_icon/project.png';
     var z;
     var map;
     
  	var marker;
  	var mapOptions;
  	var ZOOM=17;
     //Functions for current real time positions

     	function geocodePosition(pos) {
     		geocoder = new google.maps.Geocoder();
     		geocoder.geocode({
     			latLng: pos
     		},

     		function(results, status) {
     			if (status == google.maps.GeocoderStatus.OK) {
     				$('[name=address]').val(results[0].formatted_address);
     				//$('[name=lat]').val(results[0].geometry.location.lat);
     				//$('[name=lng]').val(results[0].geometry.location.lng);
     				$('[name=latitude]').val(results[0].geometry.location.A);
     				$('[name=longitude]').val(results[0].geometry.location.F);     				
                    //$(".business_coords")[0].value = results[0].geometry.location.lat + "," + results[0].geometry.location.lng;
     				$("#mapErrorMsg").hide(100);
     			} else {
     				$("#mapErrorMsg").html('Cannot determine address at this location.' + status).show(100);
     			}
     		});
     	}    	
     	function geocodeAddress() {
     		var ajson = "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyDfW9YcvZCJafB-k2c-SBaBhGOvcy5f148" + "&address=" + $('[name=address]').val() 
     		//var ajson = "https://maps.googleapis.com/maps/api/geocode/json?address=" + $('[name=full_address]').val()
     		$.ajax({
     			dataType: "json",
     			url: ajson,
     			success: function(d) {
     				z = d.results[0].geometry.location
     				$('[name=latitude]').val(z.lat);
     				$('[name=longitude]').val(z.lng);
     				marker.setPosition(z);
     				map.setCenter(z);
     			}
     		});
     	}

     	function initializeProjectEdit() {
     		var posLatLngHome
     		if($('[name=latitude]').val() == '39.9129412') //Default geolocation of nothing (near denver)
     		{
     			posLatLngHome = new google.maps.LatLng("<?= $location['latitude'] ?>", "<?= $location['longitude'] ?>");
     		} else {
     			posLatLngHome = new google.maps.LatLng($('[name=latitude]').val(), $('[name=longitude]').val());
     		}
     		marker = new google.maps.Marker({
     			position: posLatLngHome,
     			draggable: true,
     			animation: google.maps.Animation.DROP,
     			map: map,
     			title: 'Office',
     			icon: projectpng

     		});
     		google.maps.event.addListener(marker, 'dragend', function() {
     			geocodePosition(marker.getPosition());
     		});



     	}
     function initialize() {
     	var posLatLngHome = new google.maps.LatLng($('[name=latitude]').val(), $('[name=longitude]').val());
     	mapOptions = {
     		zoom: ZOOM,
     		center: posLatLngHome,
            scrollwheel: false
     	}

          map_elm = document.getElementById('map-canvas');
     	map = new google.maps.Map(map_elm, mapOptions);
     	
     	marker = new google.maps.Marker({
     		position: posLatLngHome,
     		draggable: true,
     		animation: google.maps.Animation.DROP,
     		map: map,
     		title: 'Office Position!',
     		icon: projectpng

     	});
     	google.maps.event.addListener(marker, 'dragend', function() {
      		geocodePosition(marker.getPosition());
      	});
     }