-2

I'm trying to achieve This maps effect on my system.

I have a database of properties from all over a given country stored with their Longitude and Latitude.
When a user searches (Google Places) for properties within a given city in that country, the system should query and generate a map with markers from that city only and show a boundary around that city.
I am using the city coordinates to query the stored longitudes and latitudes of the properties.

Problem
My query seems to include results from other cities too resulting in markers that fall outside the city boundary.

My Research
I followed This Link that uses Google Maps Bounds, but It is not sufficient since the city boundary is dynamic and different from the Map Bounds.

Sample MySql Query

//$min_lat,$max_lat,$min_lng,$max_lng are city coordinates gotten from google maps
//The CAST is because property coordinates are stored in VARCHAR format instead of FLOAT

SELECT properties.*         
FROM properties 
WHERE (CAST(properties.lat AS DECIMAL(10,7)) >= '$min_lat' AND CAST(properties.lat AS DECIMAL(10,7)) <= '$max_lat')
AND (CAST(properties.lng AS DECIMAL(10,7)) >= '$min_lng' AND CAST(properties.lng AS DECIMAL(10,7)) <= '$max_lng')

What I need (left) vs What I have (right)
enter image description here

Lefty
  • 808
  • 9
  • 16
  • 1
    How many times are you going to open (and delete) the same question? I have commented on your last question: You could get your **Polygon bounds** and retrieve all markers within the bounds, then, for each result, check whether it fits within the polygon area using the geometry library: https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation - now have you tried that? I see no attempt at doing that. Note: I mentioned the Polygon bounds, not the map bounds. – MrUpsidown May 06 '22 at 09:53
  • @MrUpsidown I wanted to leave one question instead of 3 similar ones. – Lefty May 07 '22 at 10:44
  • @MrUpsidown The solution with Polygon Bounds did not work for me because the Backend Query that actually brings the data to the map is the one that needed optimization to correctly identify markers from the searched region. – Lefty May 09 '22 at 02:02
  • Then you should provide your own answer otherwise your question is useless for other readers. – MrUpsidown May 09 '22 at 06:28
  • @MrUpsidown I sure will – Lefty May 09 '22 at 19:05

0 Answers0