M
M
mapleart2017-01-29 23:18:02
PHP
mapleart, 2017-01-29 23:18:02

How to get labels for visible area in google map?

Hello. Such a problem, there is a base with the coordinates of the marks. These labels are loaded onto the map using an ajax request, I pass the coordinates to it:

{
x1: map.getBounds().getSouthWest().lat(),
y1: map.getBounds().getSouthWest().lng(),
x2: map.getBounds().getNorthEast().lat(),
y2: map.getBounds().getNorthEast().lng()
}

Next, I need to write a select query that will get the labels that are in this area. Who can help?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mapleart, 2017-01-31
@mappleart

$sql ="SELECT topic_id FROM table
WHERE
(CASE WHEN {$sw_lat} < {$ne_lat} THEN topic_g_lat BETWEEN {$sw_lat} AND {$ne_lat}
ELSE topic_g_lat BETWEEN {$sw_lat} AND 180 OR topic_g_lat BETWEEN -180 AND {$ne_lat}
END)
AND
(CASE WHEN {$sw_lon} < {$ne_lon}
THEN topic_g_lng BETWEEN {$sw_lon} AND {$ne_lon}
ELSE topic_g_lng BETWEEN {$sw_lon} AND 180 OR topic_g_lng BETWEEN -180 AND {$ne_lon}
END)";

R
Rastishka, 2017-01-29
@Rastishka

So what is the problem?
The condition for the point (x, y) to enter the rectangle (x1, y1, x2, y2) is passed in the 7th grade.

V
VisualIdeas, 2017-01-30
@VisualIdeas

If you are interested in a MySQL query for finding labels in an area, then everything is simple:

SELECT * FROM `метки` 
WHERE `широта` >= `мин.широта` AND
WHERE `широта` <= `макс.широта` AND
WHERE `долгота` >= `мин.долгота` AND
WHERE `долгота` <= `макс.долгота

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question