8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google Map API 地図四隅の緯度経度取得

Posted at
function initialize() {
    var latlng = new google.maps.LatLng(35.689488, 139.691706);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
     map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    
    //getBoundsは、地図の描画が終わってからでないと正確な値がとれないので、bounds_changedイベントに登録する。  
    google.maps.event.addListener(map, 'bounds_changed', function() {
		var info = document.getElementById("info");
		info.innerHTML = "左上 "+map.getBounds().getNorthEast().lat();
		info.innerHTML += ", " + map.getBounds().getNorthEast().lng();
		info.innerHTML += "<br>";
		info.innerHTML += "右下 " + map.getBounds().getSouthWest().lat();
		info.innerHTML += ", " + map.getBounds().getSouthWest().lng();    
		info.innerHTML += "<br>";
		info.innerHTML += "中心 " + map.getBounds().getCenter().lat();
		info.innerHTML += ", " + map.getBounds().getCenter().lng();    
    });
    
         
  }

initialize();

sample

8
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?