-2

I want to be able to programmatically determine whether a location (given its longitude and latitude) are on a google map currently being displayed. That is to say, if I know the center point of the map (say it has a latitude of 38.3004709 and a longitude of -120.7063219) and the scale (e.g., zoom == 15), I should be able to calculate whether a given long/lat pair is on the map.

I guess another way of putting this question is: how many degrees of longitude across is a google map when scaled at its various values (and, obviously, how many meridians of latitude)?

Knowing that, I could then calculate programmatically whether a given lat/long pair are inside or outside the boundary of the map section currently displayed.

What I have in mind is taking address columns from tables (such as "Mokelumne Hill, California") and creating ancillary tables to hold the corresponding latitude / longitude for the addresses. Then, on selecting a certain spot on the google map at a known scale factor, the table could be queried to retrieve just that subset of addresses that fall within that range - allowing for the dynamic creation of markers, etc.

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    You could probably figure this out yourself with a little troubleshooting. – admdrew Nov 21 '13 at 22:42
  • It would actually be kind of involved; and if somebody already knows the answer ... I mean, that's the whole point of SO, isn't it? – B. Clay Shannon-B. Crow Raven Nov 21 '13 at 22:46
  • `that's the whole point of SO, isn't it?` - I would disagree - SO is for help with issues you just can't figure out after exhausting your own resources. In this specific situation you didn't demonstrate that you've already attempted to solve your issue (research or actual troubleshooting), which tends to irk others in the community. Just my opinion. But, I didn't downvote you, so maybe someone else will come along and provide an answer. – admdrew Nov 21 '13 at 22:52
  • I did google for the answer, and it's not even obvious/easy to find just how many zoom levels there are. If I knew that, it would be easier to figure out. Such as, if there are 18 zoom levels, I would theorize 20 degrees/meridians per level, and then look at something at that fine-grainest level and be able to "eyeball" things and...well, you see, it does get kind of complicated. Especially when I think there are different zoom levels available for different areas, depending on the "interestingness" and "secretivity" of the place in question. – B. Clay Shannon-B. Crow Raven Nov 21 '13 at 22:58
  • Not sure what sort of Googling you did, but I immediately found [this](https://developers.google.com/maps/documentation/staticmaps/#Zoomlevels) - `Maps on Google Maps have an integer "zoom level" which defines the resolution of the current view. Zoom levels between 0 (the lowest zoom level, in which the entire world can be seen on one map) to 21+ (down to individual buildings) are possible within the default roadmap maps view.`. That's for `Static Maps` only, however; remember that other implementations of Maps will be different (ie, Maps for Android appears to have 'unlimited' zoom levels). – admdrew Nov 21 '13 at 23:02
  • Thanks; but "21+" is still a little vague; can't be used for calculating. – B. Clay Shannon-B. Crow Raven Nov 21 '13 at 23:11
  • Sure, that's why I added as a comment, not an answer. I'm just surprised you didn't come upon that when you were searching before. – admdrew Nov 21 '13 at 23:14

1 Answers1

1

Short answer: You're looking for Map.getBounds().

However, if your actual goal is to load markers dynamically, I would advise you to use eg. MarkerClusterer or MarkerManager instead of trying to reinvent the wheel.

lambshaanxy
  • 22,552
  • 10
  • 68
  • 92