</script> <div id="googlemaps" style="width:100%; height:600px"></div> <script> var geo = new google.maps.Geocoder(); geo.geocode( { 'address': '明治神宮' }, function(result, status) { if (status == google.maps.GeocoderStatus.OK) { ...">

GoogleMap API 文字で指定した住所を地図の中心にする

/ Web / Comment[0]

テキストで入力した住所や地名などをGooglemapの中心に表示する方法です。

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<div id="googlemaps" style="width:100%; height:600px"></div>
<script>
var geo = new google.maps.Geocoder();
geo.geocode(
  { 'address': '明治神宮' },
  function(result, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      var latlng = new google.maps.LatLng( result[0].geometry.location.lat(), result[0].geometry.location.lng() );
      var myOptions = {
        zoom: 12,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("googlemaps"), myOptions);
    }
  }
);
</script>
関連記事

コメント

:
:
:
:
:
管理人のみ表示を許可