マップ上にラベルを表示する

説明

マップ上にラベルを表示するにはTLableを使うと楽です。TLableは以下のURLからダウンロードすることができます。続きは書籍で、どうぞ...
逆引きGoogle Maps APIリファレンス  詳しい解説などは逆引きGoogle Maps APIリファレンス、またはGoogle Maps APIリファレンスを参照してください。

サンプルコード [実行]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Sample</title>
<style type="text/css"><!--
.gMsg {
white-space:nowrap;
background-color:white;
font-size:10pt;
border:1px solid #fff000;
}
--></style>
<script src="http://maps.google.com/maps?file=api&amp;v=2.61&amp;key=ABQIAAAAasAJryKxWJnBFVJa487d9hTHGAxTVT7IRADYa-JdYz7xQ8IQZBSthgDZdggYpQHsmm6WYtHstQFfLA" type="text/javascript"></script>
<script type="text/javascript" src="tlabel.2.05.js"></script>
<script type="text/javascript">
//<![CDATA[
window.onload = function() {
var map = new GMap2(document.getElementById("gmap"));
map.setCenter(new GLatLng(36, 137), 6);
map.addControl(new GLargeMapControl());

var labelObj = new TLabel();
labelObj.id = "KF215";
labelObj.anchorPoint = "center";
labelObj.anchorLatLng = new GLatLng(36, 138);
labelObj.percentOpacity = 80;
labelObj.content = "<div class='gMsg'>長野県です</div>";
map.addTLabel(labelObj);
}
//]]>
</script>
<div id="gmap" style="width: 500px; height: 400px"></div>
</body>
</html>