Arash Yazdani Arash Yazdani - 29 days ago 23
Javascript Question

how to select markers in the polygon from mysql

i'm saving markers coordinates in mysql like below image

enter image description here

what i need is when user draw on maps like below image

enter image description here

i could get the shape and select markers in the shape from mysql and create a query.

for example:

$query= mysql_query("SELECT

location
FROM table WHERE Coordinates in the polygon");





i belive i need use ajax. and i'm using google maps v3

is this even possible to do that ?

PLEASE HELP, Any idea that i could somthing like that other way ??

Answer

Google maps does not provide GIS functions to select the coordinates inside a polygon. You could do using the spatial extension ( data type GEOMETRY) for mysql .. and for this you can go into that ..http://dev.mysql.com/doc/refman/5.7/en/spatial-extensions.html for mysql doc.

A simple way to select locations (points) in google maps is to use the extreme values of the coordinates of the polygon points to get the equivalent to the coordinates of the rectangle that contains the polygon vertices and then perform a select

  select location  
  from my_table 
  where location_lat >= minLat_polygon
  AND location_lat  <=  maxLat_poligon
  AND location_lng  <=  maxLng_polygon
  AND location_lng  >=  minLng_polygon