Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5985727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:34:18+00:00 2026-05-22T22:34:18+00:00

I am using a customised version of the mapview (OSMDroid version). I am using

  • 0

I am using a customised version of the mapview (OSMDroid version).
I am using custom tiles within it and I only want the user to be able to view the area where I have my custom tiles.
Is there a way to set the boundary lat longs so when they pan the map it doesn’t go past these boundaries?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:34:19+00:00Added an answer on May 22, 2026 at 10:34 pm

    Incase it helps anyone….

    I have sort of a solution that I am using, it works ok, but could definitely be better as the map can go abit too far off the screen before it jumps back!
    It uses the lat longs and works out where the map is, I set 4 coordinates which are roughly the 4 corners of the map I have found it works better if you set them slightly into the map rather exactly the corners, I then work out if the lat longs have left the screen completely.. if so it will bounce it halfway back:

    I overrode the mapview and the OnTouch event of the map

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_UP) {
    
            // (only works for north of equator)
            // * map right side (lat) can't go past the left (lat) of screen
    
            // get geopoints of the 4 corners of the screen
            Projection proj = getProjection();
            GeoPoint screenTopLeft = proj.fromPixels(0, 0);
            GeoPoint screenTopRight = proj.fromPixels(getWidth(), 0);
            GeoPoint screenBottomLeft = proj.fromPixels(0, getHeight());
    
            double screenTopLat = screenTopLeft.getLatitudeE6() / 1E6;
            double screenBottomLat = screenBottomLeft.getLatitudeE6() / 1E6;
            double screenLeftlong = screenTopLeft.getLongitudeE6() / 1E6;
            double screenRightlong = screenTopRight.getLongitudeE6() / 1E6;
    
            double mapTopLat = BoundsTopLeftCorner.getLatitudeE6() / 1E6;
            double mapBottomLat = BoundsBottomLeftCorner.getLatitudeE6() / 1E6;
            double mapLeftlong = BoundsTopLeftCorner.getLongitudeE6() / 1E6;
            double mapRightlong = BoundsTopRightCorner.getLongitudeE6() / 1E6;
    
            // screen bottom greater than map top
            // screen top less than map bottom
            // screen right less than map left
            // screen left greater than map right
            boolean movedLeft = false;
            boolean movedRight = false;
            boolean movedUp = false;
            boolean movedDown = false;
    
            boolean offscreen = false;
            if (screenBottomLat > mapTopLat) {
                movedUp = true;
                offscreen = true;
            }
            if (screenTopLat < mapBottomLat) {
                movedDown = true;
                offscreen = true;
            }
            if (screenRightlong < mapLeftlong) {
                movedLeft = true;
                offscreen = true;
            }
            if (screenLeftlong > mapRightlong) {
                movedRight = true;
                offscreen = true;
            }
    
            if (offscreen) {
                // work out on which plane it's been moved off screen (lat/lng)
    
                if (movedLeft || movedRight) {
    
                    double newBottomLat = screenBottomLat;
                    double newTopLat = screenTopLat;
    
                    double centralLat = newBottomLat
                            + ((newTopLat - newBottomLat) / 2);
                    if (movedRight)
                        this.getController().setCenter(
                                new GeoPoint(centralLat, mapRightlong));
                    else
                        this.getController().setCenter(
                                new GeoPoint(centralLat, mapLeftlong));
    
                }
                if (movedUp || movedDown) {
    
                    // longs will all remain the same
                    double newLeftLong = screenLeftlong;
                    double newRightLong = screenRightlong;
    
                    double centralLong = (newRightLong + newLeftLong) / 2;
    
                    if (movedUp)
                        this.getController().setCenter(
                                new GeoPoint(mapTopLat, centralLong));
    
                    else
                        this.getController().setCenter(
                                new GeoPoint(mapBottomLat, centralLong));
                }
    
            }
    
        }
        return super.onTouchEvent(ev);
    }}
    

    A few things I should point out if you are considering using this:

    1. I make no guarentees that it will work for your situation and you should only use it as a starting point.
    2. It will only work for areas north of the equator (I think) due to the way I’ve done the coords!
    3. It works on the “action up” of the touch event, so it takes the point where the user takes their finger off the screen. This means when the map flings it’s completely inaccurate as I could not work out where the map stopped, because of this I turned off the fling by overriding the fling event and not doing anything in it.. this does make the map a bit jolty!

    If anyone has any better solutions or can improve my code please feel free!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using online interfaces to a version control system is a nice way to have
I am using a customised version of search-theme-form.tpl When I use the search box,
I'm using svn for the first time, to maintain a custom version of Wordpress.
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
First a few definitions to keep things clear. User: A live person, using the
In my Project, I have a customised @interface GraphView: UIView . Hence GraphView is
The site is here I have opt to using the radiobutton's labels as customized
Morning All, Previously I have been using $(#WebPartWPQ2 .ms-formtable tr:contains('lblName')> td).toggleClass('changedetails'); to customise a
If I write a python script using only python standard libraries, using Python 2.6
I have a slightly customized version of the LabelFor() Html Helper found in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.