
var map, geocoder,imageSearch,infowindow,elevator;
var cm_str;
var param_adr,zaddress;
var newimg_src ;
  google.load('search', '1');
  function initialize() {
      geocoder = new google.maps.Geocoder(); 
      var myLatlng = new google.maps.LatLng(38.203655,139.658203);
      var myOptions = {
	      zoom: 5,
	      center: myLatlng,
	      tilt: 0,
	      overviewMapControl: true,
	      overviewMapControlOptions: {opened: true },
	      mapTypeId: google.maps.MapTypeId.TERRAIN
      }
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions	);      param_adr = "富士山";
      elevator = new google.maps.ElevationService();
	}
 function codeAddress(zaddress,newimg_src) {
//       markersArray[0].setMap(null); 
     var  address = zaddress;
       if (geocoder) {
        geocoder.geocode(
        { 'address': address}, function(results, status) {
       if (status == google.maps.GeocoderStatus.OK) {
//alert("codeAddress" + param_adr + newimg_src );
	   document.createElement('imgimg');
//new se();
 	   map.setCenter(results[0].geometry.location);
 	   var contentString =  address + '<br> ';
//contentString=contentString+'<img src="' + newimg_src + '"></div>';
  	   var infowindow = new google.maps.InfoWindow({
               content: contentString,
       });
           var marker = new google.maps.Marker({
                 map: map,
                 position: results[0].geometry.location
                 }); 
// ---------------------------------------------------

  var Elocations = [];
  Elocations[0]=results[0].geometry.location;

  var positionalRequest = {
    'locations': Elocations
  }

  // Initiate the location request
  if (elevator) {
    elevator.getElevationForLocations(positionalRequest, function(results, status) {
      if (status == google.maps.ElevationStatus.OK) {

        // Retrieve the first result
        if (results[0]) {

 // Open an info window indicating the elevation at the clicked position/        
infowindow.setContent( contentString + "高度： " + results[0].elevation + " M");
//var meters = results[0].elevation;
//contentString = contentString + '高度：' + meters;

//          infowindow.setPosition(clickedLocation);
//          infowindow.open(map);
        } else { alert("No results found");        }
      } else {
        alert("Elevation service failed due to: " + status);
      }
    });
  }




	   infowindow.open(map,marker);
//    google.setOnLoadCallback(OnLoad);
//	   map.openInfoWindowHtml(map,marker);
           google.maps.event.addListener(
                marker, 'click', function() {
	        map.setCenter(results[0].geometry.location); 
                map.setZoom(10);
                }); 
	       }
    else { alert("場所を特定できませんでした。" + status + address);
	}	});
	} 
     }
 function showLocation(paddress){ 
    initialize();
      var xaddress = paddress;
      param_adr = "";
　　　param_adr = xaddress;
 //alert("show" + param_adr + xaddress);
     codeAddress(xaddress,newimg_src);
    }
 function searchComplete(searcher) {
      // Check that we got results
//alert("sea11" + param_adr);
      if (searcher.results && searcher.results.length > 0) {
        // Grab our content div, clear it.
    infowindow=document.getElementById('imgimg');

        var contentDiv = document.getElementById('imgimg');
//alert("sea22" + param_adr + searcher.results.length );

        contentDiv.innerHTML = '';
        // Loop through our results, printing them to the page.
        var results = searcher.results;
//alert("sea23" + param_adr + results.length );

//        for (var i = 0; i < results.length; i++) {
        for (var i = 0; i < 1; i++) {
          // For each result write it's title and image to the screen
          var result = results[i];
//alert("sea24" + result.tbUrl);
          var imgContainer = document.createElement('div');
        //     var title = document.createElement('h2');
        // We use titleNoFormatting so that no HTML tags are left in the title     //    title.innerHTML = result.titleNoFormatting;
              var newImg = document.createElement('img');
          // There is also a result.url property which has the escaped version
          newImg.src = result.tbUrl;
    newimg_src = result.Url;
//alert("sea" + param_adr + newimg_src);
//codeAddress(param_adr);
  //        imgContainer.appendChild(title);
          imgContainer.appendChild(newImg);
              // Put our title + image in the content
          contentDiv.appendChild(imgContainer);
        }
      }
    }
 //   function OnLoad() {
 //      se();
 //   }

    function se() {

//  function OnLoad() {
      // Our ImageSearch instance.
      var imageSearch = new google.search.ImageSearch();
    
      // Restrict to extra large images only
      imageSearch.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE,
 				 google.search.ImageSearch.IMAGESIZE_MEDIUM);
   // Here we set a callback so that anytime a search is executed, it will call
      // the searchComplete function and pass it our ImageSearch searcher.
      // When a search completes, our ImageSearch object is automatically
      // populated with the results.
    imageSearch.setSearchCompleteCallback(this, searchComplete, [imageSearch]);
//      imageSearch.setSearchCompleteCallback(this, searchComplete, null);

 //   alert("onl" + param_adr);
      // Find me a beautiful car.
      imageSearch.execute(param_adr);
// codeAddress(param_adr);

    }
//    google.setOnLoadCallback(se);

  
