start_icon = new GIcon();
start_icon.iconSize = new GSize(15, 34);
start_icon.shadowSize = new GSize(19, 47);
start_icon.iconAnchor = new GPoint(19, 20);
start_icon.image = "/img/map/start_icon.png";
start_icon.iconAnchor = new GPoint(6, 20);
start_icon.infoWindowAnchor = new GPoint(5, 1);

end_icon = new GIcon();
end_icon.iconSize = new GSize(15, 34);
end_icon.shadowSize = new GSize(19, 47);
end_icon.iconAnchor = new GPoint(19, 20);
end_icon.image = "/img/map/end_icon.png";
end_icon.iconAnchor = new GPoint(6, 20);
end_icon.infoWindowAnchor = new GPoint(5, 1);


function createMarker(point,html) {
   var marker = new GMarker(point);
   GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(html);
   });
   return marker;
};

function adjustView(map, geodata, zoom){
     zoom = zoom || 0;
      // adjust rectsize and center
     var min_latitude = geodata['min_latitude'];
     var min_longitude = geodata['min_longitude'];
     var max_latitude = geodata['max_latitude'];
     var max_longitude = geodata['max_longitude'];
     var center_latitude = geodata['center_latitude'];
     var center_longitude = geodata['center_longitude'];

     var rectObj = new GLatLngBounds(new GLatLng(min_latitude,
						 min_longitude),
				     new GLatLng(max_latitude,
						 max_longitude));
     map.setCenter(new GLatLng(center_latitude, center_longitude)
		   ,map.getBoundsZoomLevel(rectObj) + zoom);
}

function showline(map, geodata){
  var encodedPoints = geodata['encoded_points'];
  var encodedLevels = geodata['encoded_levels'];

  var encodedPolyline = new GPolyline.fromEncoded({
    color: "#FF4422",
    weight: 5,
    opacity: 0.8,
    points: encodedPoints,
    levels: encodedLevels,
    zoomFactor: 32,
    numLevels: 4
    });
  map.addOverlay(encodedPolyline);

}

function showStart(map, geodata){
     var point_start = new GMarker(new GLatLng(geodata['start_latitude'], geodata['start_longitude'])
				   , start_icon);
     //GEvent.addListener(point_start, 'mouseover', function() { point_start.openInfoWindowHtml('<div style="text-align:center; width:200px;">' + 'スタート地点' + '<br />' + map_name + '</div>');});
     //GEvent.addListener(point_start, 'click', function() { point_start.openInfoWindowHtml('<div style="text-align:center; width:200px;">' + 'スタート地点' + '<br />' + map_name + '</div>');});
     map.addOverlay(point_start);
}

function showEnd(map, geodata){
     var point_end   = new GMarker(new GLatLng(geodata['end_latitude'], geodata['end_longitude'])
				   , end_icon);
    //GEvent.addListener(point_end, 'mouseover', function() { point_end.openInfoWindowHtml('<div style="text-align:center; width:200px;">' + 'ゴール地点' + '<br />' + map_name + '</div>');});
     //GEvent.addListener(point_end, 'click', function() { point_end.openInfoWindowHtml('<div style="text-align:center; width:200px;">' + 'ゴール地点' + '<br />' + map_name + '</div>');});
     map.addOverlay(point_end);
}
function showIcons(map, geodata){
  showStart(map, geodata);
  showEnd(map, geodata);
}

function showGmap(target, geodata){
   if(GBrowserIsCompatible()) {
      var map = new GMap2(target);
      Gmaps[target.id] = map;


      if(navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPod") != -1){
	map.setMapType(G_NORMAL_MAP);
      }else{
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setMapType(G_HYBRID_MAP);
        map.addControl(new GOverviewMapControl());
      }
     adjustView(map, geodata);
     showline(map, geodata);
     showIcons(map, geodata);
   }
}

