Keep user within a specified area (v3)

34 views
Skip to first unread message

davejuk

unread,
Jan 11, 2011, 1:36:29 PM1/11/11
to google-map...@googlegroups.com
Hi

My application deals with quite a small geographical area (the Severn Estuary, UK).

I want to keep the view within the general area without the user feeling too restricted. Is there any built in functionality for doing this?

If not, how would you suggest I go about doing this?

I have a pretty good grasp of the API, so I'm just looking for suggestions of how to do it in a user-friendly way.

geoco...@gmail.com

unread,
Jan 11, 2011, 3:25:15 PM1/11/11
to Google Maps JavaScript API v3
Have you tried porting Mike Williams' example from v2?

-- Larry

N.Aleksandrenko

unread,
Jan 11, 2011, 4:40:32 PM1/11/11
to google-map...@googlegroups.com
You can write it yourself. On map event 'idle' check the boundries and if they not fit in your area (you will set max left, max right, max top, max bottom) change center of the map (map.setCenter(latlng).

something like this:


    var topBound = 44.5;
    var bottomBound = 41;
    var leftBound = 22.1;
    var rightBound = 28.9;
   
    //drag end, center changed, bounds changed ...
    function mapIdle_Handler() {
       
        //limit bounds =========================================================
        var center = map.getCenter();

        if(center.lng() < leftBound) {
            map.centerMapOn(center.lat(), leftBound);
            //console.log("out of bounds: left" + center.lat() + "/" + leftBound);
        }

        if(center.lng() > rightBound) {
            map.centerMapOn(center.lat(), rightBound);
            //console.log("out of bounds: right");
        }

        if(center.lat() > topBound) {
            map.centerMapOn(topBound, center.lng());
            //console.log("out of bounds: top");
        }

        if(center.lat() < bottomBound) {
            map.centerMapOn(bottomBound, center.lng());
            //console.log("out of bounds: bottom");
        }
        // end limit bounds ====================================================
       
    }

 google.maps.event.addListener(map, 'idle', mapIdle_Handler);





--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Reply all
Reply to author
Forward
0 new messages