// Google Maps API Version 3 

var geocoder;
var map;

function initializeGoogleMaps() {
  geocoder = new google.maps.Geocoder();
}

function codeAddressGoogleMaps(address,lat,long) {
  if ((lat !='') && (long != '')) {
    var myLatLng = new google.maps.LatLng(lat,long);
    var myOptions = {
      zoom: 16,
      center: myLatLng,
      mapTypeId: google.maps.MapTypeId.ROADMAP };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var marker = new google.maps.Marker({
      map: map,
      position: myLatLng
    });

  } else {
    if (geocoder) {
      geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {

        var myOptions = {
        zoom: 16,
        center: results[0].geometry.location,
        mapTypeId: google.maps.MapTypeId.ROADMAP };

        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        var marker = new google.maps.Marker({
          map: map, 
          position: results[0].geometry.location
         });
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
  }
}

