Question

I'm using a static google map, but really this problem could apply to any maps project. I want to divide a map into multiple quadrants (of say 50x50 pixels) and label the columns as A, B, C.... and the rows as 1, 2, 3...

Next I plan to do something like,

1) Find the markers which are the farthest north, east, south, and west 2) Use that info to to define the bounding boxes of each row and column box 3) Classify each marker by its row and column (Example Marker 1 = [A,2])

A few requirements,

  • I don't know the zoom level because I let Google set the zoom level appropriately for me and I would rather not use an algorithm that is dependent on a zoom level. I do however know the locations of all of the markers that are shown on the map.

Here is an example of a map that I would like to classify the markers for, static map example link.

I found these which look like a good start, Resource 1, Resource 2

But I think I'm still in need of some help getting started. Can anyone help write out some pseudo code or post a few more resources? I'm kind of in a rut at the moment.

Thanks! Much appreciated of any help!

Was it helpful?

Solution

Ok two days into this I finally got it. Thought I would share my thoughts with people who stumble upon this later.

Following the PHP code on this site and for translating lat,lng pairs to pixel coordinates, I was able to classify the individual pixel row by the x value and the column by the pixels y value.

To calculate the zoom level, I determine the maxLat, maxLng, minLat, and minLng values defined by the collection of markers. Then I calculated the bounds of the map at a given zoom level. Finally I used a brute force method of checking if the new bounds of the map determined by the zoom level would include the bounds defined by the max,min lat,lng values of the collection of markers. Starting at zoom level 21 (max zoom on google maps) I decrement the zoom level until I find a zoom level that includes all the markers.

It seems, that the zoom level that is calculated in this method matches Google's preset zoom level selected automatically if you do not provide a zoom level for a static map.

In PHP there is a nice library to do all of this here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top