In my app I'd like to create a snapshot of a Map and as I have a custom tile-source I need to create that on my own. I am currently stuck creating a proper region that fit's a track I want to display.

So my given values are:

  • width/height of the resulting image
  • the region (coordinates) of the track
  • insets (top, bottom, left, right) I want in px

So now I need to know how to calculate a region for my needs. So basically northwest / southeast coordinates for that region.


So the end-result would be a picture of a map (using my own tiles) that would show a track a user went. And I'd like to know how to exactly calculate the bounds I need (currently I do some rule of thumb calculation).

So as a sample: I want to have an image in the end, that is 500x500px. I want there to be at least 50px of margin on each side and the track should be centered inside.

What I know are the coordinates of my track (lat/lng). So I can calculate a bounding box.

Now I need to figure out a proper zoom level (already know how to do that) but I don't know how to say: In the final image the coordinate on the top left will be this, and the on on the bottom right will be that (which would be great, cause then I would EXACTLY know which tiles to download)

Currently I hat north/east and south/west coordinates. I take the center, and use max(lat-span, lng-span) as the size. Then I take this span 1.5 times and have my coordiantes. This seems to give me reasonable images, but I was just wondering how to really calculate it.

On iOS, a MKMapView has the option to say: setVisibleMapRect:edgePadding: So basically say: this is my region and I want to have at least the given padding. So I basically need to know how this MapView calculates stuff. :) But I am not a gis guy and don't know much about calculating stuff like that :)

  • Not sure I'm fully following what you're asking. Wouldn't the result depend at least a little on the projection you're using? Could you give a specific example?
    – user1462
    May 11, 2017 at 16:34
  • Hey, thanks for helping. I'll update my question and hopefully be able to clarify a bit better,
    – Georg
    May 11, 2017 at 16:38


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.