Google maps api locate corner coordinates

断了今生、忘了曾经 提交于 2020-01-05 05:24:47

问题


QUESTION: Is there a way that I could locate what the coordinates are of corner points of the google map each time I zooms in, zooms out, or shift the map?

ELABORATING ON WHAT I MEAN:

In my google maps api code, I giving the map a specific width and height:

<style>
    #map {
        width:400px;
        height:300px;
    }
</style>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map"></div>
<script>
    var mapOptions = {
        center: new google.maps.LatLng(37.7831, -122.4039),
        zoom: 12,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById('map'), mapOptions);
</script>

Now when a user uses the scroll the look either further in the map or further out, this width and hight obviously stays the same, however the coordinates on the map located at the

top-left corner
top-right corner
bottom-left corner
bottom-right corner

change as the user shifts the map. I have been trying to find a way to obtain these coordinates but have failed in my attempts.


回答1:


map.getBounds() will return a bounds object containing the North, South, East and Western bounds of the map (as SouthWest, NorthEast).



来源:https://stackoverflow.com/questions/38534643/google-maps-api-locate-corner-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!