Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top