住所からGoogleMap

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var addr = '東京都千代田区千代田1-1-1';
var geo = new google.maps.Geocoder();
geo.geocode(
 {'address': addr},
 function(res, stat) {
  var errmsg = function(reason) { return 'Could not display map ('+reason+')' };
  if (stat != google.maps.GeocoderStatus.OK) {
   $('gmap').innerText = errmsg('GeocoderStatus not OK'); return;
  }
  pos = res[0].geometry.location;
  if (!pos.lat()) { $('gmap').innerText = errmsg('"Lat" undefined'); return; }

  $('gmap').style.width = '240px';
  $('gmap').style.height = '240px';

  new google.maps.Marker({
   position: pos, 
   map: new google.maps.Map(
    $('gmap'),
    { //ここからGoogleMapのオプション。
     mapTypeControl : false,
     zoom : 15,
     center : pos,
     streetViewControl : false,
     mapTypeId : google.maps.MapTypeId.ROADMAP
    }
   )
  });
 }
);
</script>
[googlemap id=gmap class=gmap_box]
[googlemap id=gmap2 class=gmap_box addr=washington]
[googlemap id=gmap3 class=gmap_box lat=-34.397 lng=150.644 zoom=9]

Leave a Reply